I am new to C. And I found some problem in puts and printf from C.
char str[10]; printf("Input a string.\n"); gets(str); printf("The string you input is: %s",str);
The result is if I set more than 10 char
1ang:lab lang$ ./exercise Input a string. warning: this program uses gets(), which is unsafe. 0123456789 Abort trap: 6
But when I add \n to the end of printf, printf("The string you input is: %s\n",str); The conclusion is different.
1ang:lab lang$ ./exercise Input a string. warning: this program uses gets(), which is unsafe. 0123456789 The string you input is: 0123456789 Abort trap: 6
It will print a line first, and then an error will appear. Can anyone explain this?
source share