F
fuzhen
I was talking with someone about fgets and he said that fgets puts the
\n in a string but not \0. I decided to test this assumption because my
documentation didn't say if fgets put \0 after a string literal. Strlen was
what I used to decide the \0 was not added. How can it be added for a
string? My code.
int main (void) {
char input[10];
fgets (input, sizeof(input), stdin);
printf ("%i\n", strlen(input));
}
One more character than what was typed printf reported.
Bill
if(input[strlen(input) - 1] == '\n')
{
input[strlen(input) - 1] = '\0';
}