Re: %n conversion in sscanf/VC++ 6-solved

Discussion in 'C++' started by Anonymous, Oct 30, 2003.

  1. Anonymous

    Anonymous Guest

    Anonymous wrote:
    > The following code does not behave as I expect
    > 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 final %n in the control string is not reached, since there is no
    whitespace at the end of the string s. Therefore, no assignment is made
    to i, and the value there was left over from a previous assignment.

    > (remove caps to get e-mail)
     
    Anonymous, Oct 30, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pramod
    Replies:
    22
    Views:
    1,846
    Lew Pitcher
    Jan 6, 2004
  2. Mike

    sscanf and c++!

    Mike, Jun 8, 2004, in forum: C++
    Replies:
    3
    Views:
    3,557
  3. Matt

    sscanf feature in C++?

    Matt, Oct 18, 2004, in forum: C++
    Replies:
    15
    Views:
    19,023
    Default User
    Oct 19, 2004
  4. Darrell Grainger

    Re: Unitialized Memory Read In sscanf()

    Darrell Grainger, Jun 24, 2003, in forum: C Programming
    Replies:
    1
    Views:
    820
    Alan Balmer
    Jun 24, 2003
  5. Michael Bacarella
    Replies:
    26
    Views:
    1,347
    harri
    Nov 20, 2007
Loading...

Share This Page