473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

%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"
01234567890123456789012345678901234567890123456789 0
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.

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

Jul 19 '05 #1
1 4178
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"
01234567890123456789012345678901234567890123456789 0
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.
sh************@computer.org (remove caps to get e-mail)


Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Brad | last post by:
I have a problem in that I need to change a large decimal value into its hex equivalent. The largest decimal value I need to represent as hex is 25516777215. The problem here is that this number...
3
by: ling | last post by:
Hi, I'm trying to do fscanf from a file with integers. I've tried using both %d and %i hoping that I would figure out their difference. When I checked the man pages, the only difference I...
4
by: salsipius | last post by:
I have a char array say -->char in = "0004 000A" with a space between the 2 HEX numbers that I am trying to read into a long so I can test individual bits of the number. using sscanf(in,"%x",...
6
by: ATS | last post by:
INF: Has anyone made a CString, sprintf, and sscanf for .NET? Please help, I want to code with PURE .NET (i.e. pure CLR). No MFC, No ATL, no C-Run Time Library. But I want CString, sprintf,...
8
by: Eric Lilja | last post by:
Hello, I have IPv4-numbers in the following format: "\\x0A\\x11\\x8C\\x01" Now I need each byte as an int. I wrote the following test program: #include <stdio.h> #include <stdlib.h> static...
18
by: Andrew | last post by:
Hi, I have a scenario in which both the source and format string for a sscanf() call is selected *at runtime*. The number of format conversions/substitutions is known as well as the maximum...
9
by: GrispernMix | last post by:
bool variant_t::Convert( fieldtype_t newType ) { if ( newType == fieldType ) { return true; } // // Converting to a null value is easy. //
18
by: moni | last post by:
I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using
15
by: bcpkh | last post by:
Hello All I have a simple task that is driving me crazy. A string representing a duration in the following format is passed to my application, a function is dedicated to convert this duration to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.