Please see the Example/* SSCANF.C: This program uses sscanf to read data items
* from a string named tokenstring, then displays them.
*/#include <stdio.h>void main( void )
{
char tokenstring[] = "1234";
int i;
float fp;
sscanf( tokenstring, "%d", &i );
sscanf( tokenstring, "%f", &fp ); printf( "Integer: = %d\n", i );
printf( "Real: = %f\n", fp );
}
* from a string named tokenstring, then displays them.
*/#include <stdio.h>void main( void )
{
char tokenstring[] = "1234";
int i;
float fp;
sscanf( tokenstring, "%d", &i );
sscanf( tokenstring, "%f", &fp ); printf( "Integer: = %d\n", i );
printf( "Real: = %f\n", fp );
}
1.用atoi()函数;
2.自己处理:
int StrToInt(char *tokenstring[])
{
int iValue;
char temp;
for (int i=0;i<strlen(tokenstring);i++)
{
temp=tokenstring[i];
iValue+=(temp-'0')*Power10(i);
}
}
int Power10(int i)
{
int value=1;
for(int j=0;j<i;j++)
value*=10;
return value;
}
{
int Value=0; while( *s != 0 )
Value = Value*10 + ( *(s++) - '0' ); return Value;
}
{
int Value=0;
while( *s != 0 )
Value = Value*10 + ( *(s++) - '0' );
return Value;
}