Did you read the quote in my post as well though? You can't just blat over the last character, presuming it's a newline, 'cos it might not be.
Originally posted by Monster
line[strlen(line)-1] = '\0'; /* remove newline character */
A safer way is
This does do 2 calls to strlen() which is a bit of an overhead. Depending on your app, it may be better to do one call, and store the result in another variable, using that in the above code.
if (line[strlen(line)-1] == '\n') line[strlen(line)-1] ='\0';