%n conversion in sscanf/VC++ 6

From: Anonymous (nospam_at_noISP.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 01:16:27 GMT

The following code does not behave as I expect, and I cannot understand
why not.
        int i1,i2,i0; double x,y,z; char s[100];
        k=sscanf(s,"%n%le %n%le %n%le %n",&i0,&x,&i1,&y,&i2,&z,&i);

When s=" 1.0000000E+06 1.0000000E+04 0.0000000E+00"
         012345678901234567890123456789012345678901234567890
         0 1 2 3 4 5

execution of the sscanf produces the results

        i0=0
        i1=21
        i2=38
        k=3
        x=1e6, y=1e4, z=0

all as expected, but i=17, when I expect 51 (the total number of
characters read in this sscanf.

This is being run under Windows XP, Visual C++ 6 sp5.

sherNOwoodSPAM@computer.org (remove caps to get e-mail)



Relevant Pages

  • Re: sscanf problem
    ... I have to interface some C code in C++, but I had a problem with sscanf ... If the input line is actually 9 characters or longer, ... buffer be null-terminated. ... uninitialized, so if it contains a valid pointer, that's purely by ...
    (comp.lang.c)
  • Re: String parsing question
    ... Dan Pop spoke thus: ... However, I'd rather not use sscanf, for two reasons: ... term alphanumeric to distinguish the "other" characters from the delimiters. ...
    (comp.lang.c)
  • Re: formatted input/output question
    ... text file, for example, "12345abcde678", I want to parse ... If you want to read three characters, then two, then two, then three ... will not be part of the standard library) and using sscanf(). ...
    (comp.lang.c)
  • Re: Newbie Q: Fraction to double
    ... I won't be able to use your sscanf command. ... > unwise to go on to pass it to fgets(). ... > as many characters as there are in the input line (i.e., ... > parser for the input lines, replacing the entire sscanf and company, ...
    (comp.lang.c)
  • Re: Newbie Q: Fraction to double
    ... unwise to go on to pass it to fgets(). ... The argument to sscanf(), however, are wrong. ... as many characters as there are in the input line (i.e., ... Reading email is like searching for food in the garbage, ...
    (comp.lang.c)