Hints for using "scanf" (was Re: ... scanf interpretation question(s))
Doug Gwyn
gwyn at smoke.BRL.MIL
Thu Jan 18 00:55:39 AEST 1990
In article <583 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
>If you want to analyze interactive (or unpredictable) input,
>my advice is to read a complete line with "fgets" (avoid "gets"!!)
>or read up to some other significant token with "gets/fgets".
>After that, use "sscanf" on the buffer you just read.
Yes, this is much cleaner than using fscanf(). You can also use
some of the str*() functions instead of or in addition to sscanf()
to parse the buffer.
Many X3J11 members disliked including *scanf() in the Standard, but
because it was widespread existing practice we had to do it. Same
for gets().
More information about the Comp.std.c
mailing list