Curious Behaviour of "sscanf"
Larry Jones
scjones at sdrc.UUCP
Mon Jun 20 05:43:58 AEST 1988
In article <236 at c10sd3.StPaul.NCR.COM>, anderson at c10sd3.StPaul.NCR.COM (Joel Anderson) writes:
> On a call to sscanf as follows:
> if (sscanf(argv[3],"X=(%d,%d)",&y,&z) == 2)
> and an input string where argv[3] is as follows:
> "X=(1,4"
> (not including the double quotes), why does sscanf in this case evaluate to
> true? Sscanf matches the number of arguments but does not continue parsing
> the control string (i.e. true even though the closing paren is missing)?
>
> Perhaps this is correct - is it?
Yep, that's the way scanf works. The problem is not that scanf doesn't
continue parsing the control string -- it does -- the problem is that it
doesn't have any way to let you know there was a problem. The definition
of scanf states that it returns the number of items successfully converted;
since it successfully converted 2 arguments, that's what it returned and
that's what you were expecting.
----
Larry Jones UUCP: ...!sdrc!scjones
SDRC AT&T: (513) 576-2070
2000 Eastman Dr. BIX: ltl
Milford, OH 45150
"When all else fails, read the directions."
More information about the Comp.lang.c
mailing list