Re: removing newline character from the buffer read by fgets
- From: "junky_fellow@xxxxxxxxxxx" <junky_fellow@xxxxxxxxxxx>
- Date: 28 Nov 2006 04:19:12 -0800
On Nov 28, 3:27 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
junky_fel...@xxxxxxxxxxx said:
On Nov 28, 1:59 pm, Richard Heathfield wrote:
The principal objection I have to your code is that it fails to provide a
way to distinguish between a line that has been read completely and a
line that has been read only partially because of insufficient space in
the buffer.
For that I would change the function to return the number of bytesmight reasonably reserve 0 for an exceptional condition, leaving the user
read.That is a reasonable approach. I would suggest a size_t type for this. You
to enquire of ferror() to find out whether Something Really Bad happened or
whether the routine simply couldn't find any data to stuff into the buffer
(i.e. encountered EOF on the first getc call).
Using 0 or some other value (negative value) for an exceptional
condition
is a good idea. thanks for that.
Regarding "size_t", I used the type "int" for "bytes_read" as its value
will
never be greater than "n". The type of "n" is "int", so I thought
"bytes_read"
should also be "int".
Is there any special reason for using size_t for "bytes_read" ?
.
- Follow-Ups:
- Re: removing newline character from the buffer read by fgets
- From: santosh
- Re: removing newline character from the buffer read by fgets
- From: Richard Heathfield
- Re: removing newline character from the buffer read by fgets
- References:
- removing newline character from the buffer read by fgets
- From: junky_fellow@xxxxxxxxxxx
- Re: removing newline character from the buffer read by fgets
- From: Richard Heathfield
- Re: removing newline character from the buffer read by fgets
- From: junky_fellow@xxxxxxxxxxx
- Re: removing newline character from the buffer read by fgets
- From: Richard Heathfield
- Re: removing newline character from the buffer read by fgets
- From: junky_fellow@xxxxxxxxxxx
- Re: removing newline character from the buffer read by fgets
- From: Richard Heathfield
- removing newline character from the buffer read by fgets
- Prev by Date: Re: Reading a string of unknown size
- Next by Date: Re: scanf behaviour
- Previous by thread: Re: removing newline character from the buffer read by fgets
- Next by thread: Re: removing newline character from the buffer read by fgets
- Index(es):