fgets() returns NULL at EOF??

karl at haddock karl at haddock
Wed Sep 10 03:20:00 AEST 1986

Bader at b.psy.cmu.edu writes:
>[concerning the return value of gets()/fgets()]
>Neither of your suggestions (# of characters, EOF or 0) makes any more sense
>to me than the current behavior, which seems perfectly reasonable.  If
>nothing better is being offered, why waste time arguing about it?

In the current behavior, the value on successful return is the buffer arg --
a useless value already available to the user.  The character count is not
available except by calling strlen(), which is somewhat redundant since the
library function already has the value (or enough information to construct
it in constant time).

There is a similar duplication of effort in strcpy() followed by strcat(),
for which reason I think strcpy() should've returned the END of the string
(pointer to the '\0') instead of the beginning.  I need that value more
often than I need a copy of the first argument.

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

More information about the Comp.lang.c mailing list