Welcome, Guest. Please login or register.

Author Topic: I need help with C(++)  (Read 4762 times)

Description:

0 Members and 2 Guests are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: I need help with C(++)
« on: April 04, 2003, 10:34:38 AM »
@Karlos

Just being pedantic here, but:

a) If the stream end in immeditate EOF, your code trash memory *before* the buffer [0-1]. Not good.

b) The last char is not always a newline. If the stream ends (EOF) you now kill the last perfectly valid char. Not good.

Make it:

/* If the last char is a newline, kill it */
if (len && p->data[len-1] == '\n')
{
  p->data[len-1] = '\0';
}

/* Note to anyone who thinks the char could be '\r' too: PC stdio libs have automagic "\r\n" -> "\n" at input and automagic "\n" -> "\r\n" at output. Or at least should have. :-) */