473,769 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sscanf not working , why?

hi,
1) first test program code

#include <stdio.h>

int main(void)
{
char * file = "aaa 23 32 m 2.23 ammasd";
int i2,i3;

float f;
char firststr[23];
char thirdchar;
char laststr[23];
sscanf(file,"%s ",firststr) ;
printf("%s\n" ,firststr);
sscanf(file,"%i ",&i2);
printf("%i\n",i 2);

sscanf(file,"%i ",&i3);
printf("%i\n",i 3);

sscanf(file,"%c ", &thirdchar);
printf("%c\n",t hirdchar);
return 0;
}
the prog doesn't print 23 32 ,it emits the result

aaa
-1073748344
1073792608
a

why?

while
2) second test program code

#include <stdio.h>

int main(void)
{
char * file = "aaa 23 32 m 2.23 ammasd";
int i2,i3;

float f;
char firststr[23];
char thirdchar;
char laststr[23];
int count;
count;
/*sscanf(file,"% s",firststr) ;
printf("%s\n" ,firststr);
sscanf(file,"%i ",&i2);
printf("%i\n",i 2);

sscanf(file,"%i ",&i3);
printf("%i\n",i 3);

sscanf(file,"%c ", &thirdchar);
printf("%c\n",t hirdchar);*/
count =
sscanf(file,"%s %i%i%c%f%s",fir ststr,&i2,&i3,& thirdchar,&f,la ststr);
printf("count:% d, %s %i %i %c %f %s\n", count, firststr, i2,i3,
thirdchar,f,las tstr);
return 0;
}

gives me the result

count:4, aaa 23 32 36.759842 å…°

how can i get the right result? thanks

baumann@pan

Nov 14 '05
10 5470
pete <pf*****@mindsp ring.com> writes:
Martin Ambuhl wrote:

baumann@pan wrote:
> also the msdn library vs.net 2003 has the example
>
> #include <stdio.h>
> void main( void )

^^^^
Anything giving illegal definitions of main should not be used.


I don't think that's illegal.
I think it falls under the clause

N869
5.1.2.2.1 Program startup
[#1]
"or in some other implementation-defined manner."


Which makes it legal only if the implementation defines it to be
legal, i.e., if the implementation *explicitly* documents it supports
"void main(void)". I don't know whether whatever compiler the library
is used with actually documents this (I sincerely hope it doesn't).

Of course, even if it's legal, that doesn't imply that it's not evil.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #11

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

Similar topics

3
4785
by: whisper | last post by:
Hello: I am trying to write code to read in a bunch of lines from stdin, each containing a (variable) number of integers and writing each integer in a separate line to stdout. I came up the code below. I could not get sscanf to work because it does not increment its position
4
4258
by: smshahriar | last post by:
Hi, I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00
82
12644
by: zardoz | last post by:
I've got this problem: unsigned long long lTemp; char cLargeNum="1324567890"; sscanf(clargeNum,"%llu",&lTemp); which under Win32 isn't working*. My program needs to compile under posix so no Win32 specials allowed....
4
2030
by: baumann | last post by:
hi all there has 2 program 1) the first test program code #include <stdio.h> int main(void) {
5
6405
by: jchludzinski | last post by:
I'm using strtok() to parse thru a line and read different numbers: float value; char *token; token = strtok( line, " " ); .... sscanf( token, "%f", &value ); These results are less precise than I had expected:
22
2962
by: Superfox il Volpone | last post by:
Hello I have some problem with sscanf, I tryed this code but it doesn't works : char* stringa = "18/2005" char mese; char anno; int i_letture; i_letture = sscanf(stringa, "%2s/%4s", &mese, &anno);
4
1812
by: lynx_ace | last post by:
Hi everyone. I need a little bit help here...I have an assignment and it is working fine until the last part which I can't solve. So here's the code in simple form #define maxlength 200 while( fgets( command, MAXLLENGTH, stdin ) != NULL ) {
20
21441
by: AMP | last post by:
Hello, Anybody know if anything exists like sscanf in c. I found a few things OL but most were pretty old. Maybe something has come along since 2004? Thanks Mike
5
2314
by: a | last post by:
After reading FAQ comp.lang.c section 12 and googling again, still there is no threads talking about reading a series of numbers. The input files, somehow structured, is exemplified below: <presence/absence of n space/tab on the first n lines> 12 <presence/absence of n space/tab here>0<presence/absence of n space/tab here>90 10 23 43 0 0 0 0 0 0 0 90 0 0 0 0 88 0 0 0 ...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.