B
baumann@pan
hi all
there has 2 program
1) the 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];
int count;
count;
/*
sscanf(file,"%s",firststr);
printf("%s\n" ,firststr);
sscanf(file,"%i",&i2);
printf("%i\n",i2);
sscanf(file,"%i",&i3);
printf("%i\n",i3);
sscanf(file,"%c", &thirdchar);
printf("%c\n",thirdchar);
*/
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,laststr);
return 0;
}
gives me the result
count:4, aaa 23 32 36.759842 å…°
2) test program 2
#
- Hide quoted text -
- Show quoted text -
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",i2);
sscanf(file,"%i",&i3);
printf("%i\n",i3);
sscanf(file,"%c", &thirdchar);
printf("%c\n",thirdchar);*/
count = sscanf(file,"%s %i %i %c %f
%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
printf("count:%d, %s %i %i %c %f %s\n", count, firststr, i2,i3,
thirdchar,f,laststr);
return 0
;
}
this give me the right result,
count:6, aaa 23 32 m 2.230000 ammasd
but the only difference between the first example is the space between
the format string,
i.e.
i changed
count =
sscanf(file,"%s%i%i%c%f%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
to
count = sscanf(file,"%s %i %i %c %f
%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
last, it works,
why?thanks
baumann@pan
there has 2 program
1) the 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];
int count;
count;
/*
sscanf(file,"%s",firststr);
printf("%s\n" ,firststr);
sscanf(file,"%i",&i2);
printf("%i\n",i2);
sscanf(file,"%i",&i3);
printf("%i\n",i3);
sscanf(file,"%c", &thirdchar);
printf("%c\n",thirdchar);
*/
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,laststr);
return 0;
}
gives me the result
count:4, aaa 23 32 36.759842 å…°
2) test program 2
#
- Hide quoted text -
- Show quoted text -
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",i2);
sscanf(file,"%i",&i3);
printf("%i\n",i3);
sscanf(file,"%c", &thirdchar);
printf("%c\n",thirdchar);*/
count = sscanf(file,"%s %i %i %c %f
%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
printf("count:%d, %s %i %i %c %f %s\n", count, firststr, i2,i3,
thirdchar,f,laststr);
return 0
;
}
this give me the right result,
count:6, aaa 23 32 m 2.230000 ammasd
but the only difference between the first example is the space between
the format string,
i.e.
i changed
count =
sscanf(file,"%s%i%i%c%f%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
to
count = sscanf(file,"%s %i %i %c %f
%s",firststr,&i2,&i3,&thirdchaÂr,&f,laststr);
last, it works,
why?thanks
baumann@pan