Mail Archives: djgpp/1996/04/07/00:35:30
On Wed, 3 Apr 1996, Alexander V. Lukyanov wrote:
> Shouldn't scanf exit if match failed and eof is not reached?
The ANSI standard says this about f?scanf (in 7.9.6.2 and 7.9.6.4):
"... If there are insufficient arguments for the format, the
behavior is undefined. If the format is exhausted while
arguments remain, the excess arguments are evaluated (as always)
but are otherwise ignored.
... The `fscanf' function returns the value of the macro EOF if
an input failure occurs before any conversion. Otherwise, the
`fscanf' function returns the number of input items assigned,
which can be fewer than provided for, or even zero, in the event
of an early matching failure."
For `sscanf' it says the same (7.9.6.6) but also adds:
"... Reaching the end of the string is equivalent to
encountering end-of-file for the `fscanf' function. If copying
takes place between objects that overlap, the behavior is
undefined."
I guess reaching the end of the string in `sscanf' is the only equivalent
of an ``input failure'' too.
- Raw text -