Explain this sscanf behavior.

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Jul 8 14:13:15 AEST 1990


In article <1990Jul6.181830.2549 at tc.fluke.COM> mason at tc.fluke.COM (Nick Mason) writes:
>	int  a, b = -99, x;
>	x = sscanf("123x", "%d%n", &a, &b);
>	printf("x=%d, a=%d, b=%d\n",x,a,b);
>	x = sscanf("123", "%d%n", &a, &b);
>	printf("x=%d, a=%d, b=%d\n",x,a,b);
>What is the CORRECT output according to the standard???

You've uncovered an interesting feature:  Although the %n specifier
does not consume input, it can still have an "input failure" when
EOF was encountered during preceding conversions that matched non-
empty sequences.

>compiler C:
>	x=1  a=123  b=3
>	x=1  a=123  b= -99
>I'm confused????!!!!! Compiler C is "100% ANSI compatible".????

It might be; it did return the right answer in this particular case.

P.S.  This is not an official interpretation; if it bothers you,
please send an official request for interpretation to CBEMA X3.



More information about the Comp.std.c mailing list