Article View: comp.std.c
Article #1468Explain this sscanf behavior.
From: Nick Mason
Date: Fri, 06 Jul 1990 18:18
Date: Fri, 06 Jul 1990 18:18
54 lines
1281 bytes
1281 bytes
What should sscanf do with the following? Does anyone
have the ANSI standard and shed some light on the following?
I would like "hard" replies, not "I think it should ....".
Thanks in advance.
Given:
char *buf="123";
char *str="123x";
int a, b, x;
b = -99;
x = sscanf(str, "%d%n", &a, &b);
printf("x=%d, a=%d, b=%d\n",x,a,b);
x = sscanf(buf, "%d%n", &a, &b);
printf("x=%d, a=%d, b=%d\n",x,a,b);
What is the CORRECT output according to the standard???
I tried this with 3 different compilers and got the following:
compiler A:
x=1 a=123 b=3
x=1 a=123 b=3
compiler B:
x=1 a=123 b=3
x=1 a=123 b=4 <-- yes 4.
compiler C:
x=1 a=123 b=3
x=1 a=123 b= -99
I'm confused????!!!!! Compiler C is "100% ANSI compatible".????
Nick.
Technical Details
Message-ID:
<1990Jul6.181830.2549@tc.fluke.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!uw-beaver!fluke!masonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!uw-beaver!fluke!mason From: mason@tc.fluke.COM (Nick Mason) Newsgroups: comp.std.c,comp.lang.c Subject: Explain this sscanf behavior. Keywords: sscanf ANSI Message-ID: <1990Jul6.181830.2549@tc.fluke.COM> Date: 6 Jul 90 18:18:30 GMT Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 54