Mail Archives: djgpp/2001/04/10/07:45:15
Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
> On Mon, 9 Apr 2001, Jack Klein wrote:
>> There is nothing that scanf() can do that fgets() followed by other
>> functions, including sscanf(), can't do as well or better.
> This argument goes both ways: scanf and fgets+sscanf are functionally
> equivalent. A C programmer should master both, IMHO.
Actually, I'd claim that both the above are subtly wrong.
scanf() (with a cleverly designed format string) can skip over
"infinitely" large input without actually copying them into
program-internal storage --- you can't do that with fgets()+sscanf().
OTOH scanf() is not functionally equivalent to fgets()+sscanf() ---
the problem is ambiguous input. fgets() lets you go back and re-try.
With scanf(), you have to split up the input into small fragments (or
abuse scanf() to behave like fgets(), and sscanf() later).
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -