Mail Archives: djgpp-workers/2003/08/08/04:57:23
Eli said:
> > From: Martin Stromberg <eplmst AT epl DOT ericsson DOT se>
> > Date: Fri, 8 Aug 2003 09:01:31 +0200 (MET DST)
> > >
> > > OTOH, DJGPP will output 0 even if the input string is "" in the code
> > > quoted above. So, DJGPP's sscanf is broken, too, just in a different
> > > way :-)
> >
> > The second return value they are talking about is when the code is
> > changed to
> >
> > #include <stdio.h>
> >
> > int main()
> > {
> > char buff[4];
> > int rc = sscanf("123", "%[0123456789]%*c", buff);
> > printf("%d\n", rc);
> > return 0;
> > }
>
> Thanks for this, but I still don't understand why returning a 0 when
> the string is "" is a bug. Can you explain?
Because the standard says
" The sscanf function returns the value of the macro EOF if an
input failure occurs before any conversion. Otherwise, the
sscanf 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."
If the string is "" no conversion is done, hence EOF should be
returned. The string "abc" should also make it return EOF, if I've
understood correctly.
Right,
MartinS
- Raw text -