I am new in C. And I found some problem in puts and printf of C.
char str[10];
printf("Input a string.\n");
gets(str);
printf("The string you input is: %s",str);
The output is these if I put 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
at the end of printf, printf("The string you input is: %s\n",str);
the output 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 first print the string and then occur the error. Could someone explain it?