Take for example rc = scanf("%f", &flt);
with the input 42ex
. An implementation of scanf
would read 42e
thinking it would encounter a digit or sign after that and realize first when reading x
that it didn't get that. Should it at this point push back both x
and e
? Or should it only push back the x
.
The reason I ask is that GNU's libc will on a subsequent call to gets
return ex
indicating they've pushed back both x
and e
, but the standard says:
An input item is read from the stream, unless the specification includes an n specifier. An input item is defined as the longest sequence of input characters which does not exceed any specified field width and which is, or is a prefix of, a matching input sequence[245] The first character, if any, after the input item remains unread. If the length of the input item is zero, the execution of the directive fails; this condition is a matching failure unless end-of-file, an encoding error, or a read error prevented input from the stream, in which case it is an input failure.
I interpret this as since 42e
is a prefix of a matching input sequence (since for example 42e1
would be a matching input sequence), which should mean that it would consider 42e
as a input item that should be read leaving only x
unread. That would also be more convenient to implement if the stream only supports single character push back.