-
Quote:
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.
-
Quote:
Originally posted by Hammer
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';
Yes, I did read your quote and I know what you mean. My response was about the first quote you wrote.
Maybe it was better to respond to both quotes the same time.
Cheers,
Monster
-
Thx a lot guys...you are very helpful