fgets() returns NULL at EOF??

karl at haddock karl at haddock
Thu Sep 4 03:32:00 AEST 1986


sun!guy (Guy Harris) writes:
>Now, you can ask "why does 'fgets' return a value of type 'char *'?"  at
>this point.  It returns a pointer to the buffer that it just filled in;
>obviously *somebody* found this useful, although I don't find it so.

Me neither.  It sounds like a "why not?" situation.

>If "fgets" didn't return that pointer, it could have been defined as
>returning a value of type "int" instead, and that value would have been 0 on
>success and EOF on failure.

Better yet, return the number of characters read (so 0 on failure).

>It's too late to change it, though.

Not without changing the name again.  (That's how fgets() evolved from
gets(), though the latter still exists.)

Karl W. Z. Heuer (ima!haddock!karl; karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list