Originally posted by Monster
Oops.....
Code:
line[strlen(line)-1] = '\0'; /* remove newline character */
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.
A safer way is
Code:
if (line[strlen(line)-1] == '\n') line[strlen(line)-1] ='\0';
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.