Hello everyone I've a problem with this code:
#define MAX_LIMIT 5
#include <stdio.h>
#include <stdlib.h>
int main()
{
char S[MAX_LIMIT];
scanf("%s", S);
printf("%s\n", S);
}
As you can see the "MAX_LIMIT" value is 5 so I don't want the sting "S" to have more than 5 chars... The problem occurs when I give in input words which exceed this limit.
For example, if I wrote "1234567890" I expect the printf to print "1234" but it prints "1234567890" and I don't know why...
I've also tried to add fflush(stdin); or getchar(); after the input but it doesn't work
I've tried with fgets(S, MAX_LIMIT, stdin); and it works but I still don't understand why if I use scanf it doesn't...