 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Anonymous Guest
|
Posted: Thu Oct 30, 2003 1:16 am Post subject: %n conversion in sscanf/VC++ 6 |
|
|
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
|
Posted: Thu Oct 30, 2003 5:05 pm Post subject: Re: %n conversion in sscanf/VC++ 6-solved |
|
|
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 |
|
 |
|
|
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
|
|