
Newbie question about fgets() Function
Quote:
>A newbie question:
>The way I _want_ fgets() to work is for it to read until n-1 characters
>are transfered to the input buffer or until it encounters a newline
>(i.e., CR-LF), in which case it captures the newline. I'm happy to
>replace the CR with a NULL to form a proper string.
Within C lines are by definition terminated with a linefeed (ASCII value 10)
character. If the file is opened in text more the library will convert
automatically between the system's line convention and this convention.
Thus if you are using a system that uses CR-LF to terminate a line the
library will convert all instances of these to plain LF with input from
a file opened in text mode.
Quote:
>The way it _is_ working is that it reads the stream until it sees the
>newline, but then places (get ready for it) a LF-NULL combination in the
>buffer. That's right, a hex 0D-00. Huh?
This looks confused. LF is a linefeed with value 10 (0x0a) in ASCII, CR is
a carriage return with ASCII value 13 (0x0d).
What do you actually see?
--
-----------------------------------------
-----------------------------------------