Why isn't there a "safe" version of the gets() function that WON't
write past the end of its buffer, even if the stream it's reading
doesn't contain sufficient newline characters?
The strcpy() and strcmp() functions have their "n" counterparts: strncpy(),
strncmp() - why not gets()?
Brian Rhodefer
There is: fgets(). It also requires you to supply the stream as an
argument, but that's not much trouble.
--
Barry Margolin
System Manager, Thinking Machines Corp.
bar...@think.com {uunet,harvard}!think!barmar
There is (sort of): see the fgets() function manual page [fgets(3)].
It's not quite the same as gets(). The *real* question is: *why*, oh why,
does this bug-function *still* live? Why can't it die? It's even inside
the ANSI C library. Why?? The only reason I can figure is political finagling,
but that doesn't really answer the question. I should think that everybody
would be happy to get rid of it. I can only suppose that it must be due to
the efforts of some stodgy cardiac pace-maker manufacturer who doesn't want
to change their dusty-deck code :) ... Perhaps P. J. Plauger, who has given
insight into the internal processes of the ANSI standardization committee, can
help...
>The strcpy() and strcmp() functions have their "n" counterparts: strncpy(),
>strncmp() - why not gets()?
gets() is not part of the string library.
I don't know who wrote the string library. Dennis Ritchie wrote the stdio
library. I suspect that you are seeing the effects of different people
designing different libraries.
>Brian Rhodefer
ku...@grogatch.celestial.com (Kurt Cockrum)