On Wed, Nov 25, 2009 at 2:48 PM, johnmatthews2000 <[email protected]> wrote:
> If fgets() on a FILE* returns 0 indicating end-of-file,

fgets() returns on EOF, *or* an error (someone just unplugged that USB
pen you were reading. I used to use the example of someone removing
the floppy disk, but that seems a bit old hat now.)

> is it safe to call it again? That is, is it guaranteed that the function
> will return 0 again with no undesirable side effects?

I'd say no. Because it might not be EOF. You distinguish between the
two using feof() and ferror(). And if you're going to that trouble,
you might as well ensure there isn't a second attempt to read.

The Standard (from my quick skim) is silent on what the behaviour
should/may/must be on a second call on a stream that has already
returned one error.

> This is in C, if it makes a difference.

I think we need a bit more background to the reason for the question ;)

-- 
PJH

http://shabbleland.myminicity.com/
http://www.chavgangs.com/register.php?referer=9375
http://www.kongregate.com/?referrer=Shabble

Reply via email to