Substitute for gets()
Henry Spencer
henry at utzoo.uucp
Thu Feb 9 08:35:54 AEST 1989
In article <721 at hscfvax.harvard.edu> xmjschm at hscfvax.harvard.edu (MJSchmelzer) writes:
>Given that gets() is unsafe because it doesn't check its input,
>what form of scanf() should be used?
The replacement for gets() is fgets(), not scanf(). In general it is both
safer and more satisfactory to read a line into a buffer with fgets() and
then pick it apart by whatever means is appropriate, which might possibly
include sscanf() although it isn't really satisfactory, than to try to use
scanf() directly on the input. Printf() was an experiment that worked; the
same cannot be said of scanf(), at least not with anywhere near the same
level of enthusiasm.
--
Allegedly heard aboard Mir: "A | Henry Spencer at U of Toronto Zoology
toast to comrade Van Allen!!" | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list