[comp.lang.c] Help needed with <fgets> and strings -- bad suggestion

minow@decvax.UUCP (03/30/87)

In article <725@instable.UUCP> amos%nsta@nsc.com (Amos Shapir) comments
on the return value for fgets() -- noting that fgets() returns a pointer
to the start of the buffer:

  >This is done so you can do things like strcmp("END", fgets(...))

This is not a good idea -- if you try this at the end of the file
(or if an error occurs), strcmp() may crash when it tries to derefence
the NULL return.

It is seldom a good idea to try to save a microsecond (or a few
bytes of memory) when the alternative is a latent bug just waiting
to happen.

Martin Minow
decvax!minow