C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

%n conversion in sscanf/VC++ 6

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Thu Oct 30, 2003 1:16 am    Post subject: %n conversion in sscanf/VC++ 6 Reply with quote



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.

[email]sherNOwoodSPAM (AT) computer (DOT) org[/email] (remove caps to get e-mail)

Back to top
Anonymous
Guest





PostPosted: Thu Oct 30, 2003 5:05 pm    Post subject: Re: %n conversion in sscanf/VC++ 6-solved Reply with quote



Anonymous wrote:
Quote:
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.

Quote:
sherNOwoodSPAM (AT) computer (DOT) org (remove caps to get e-mail)


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.