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 );
}

解决方案 »

  1.   

    使用函数atoi()就可以了,不需要那么麻烦
      

  2.   

    两种方法:
    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;

    }
      

  3.   

    int StrToInt(char *s)
    {
      int  Value=0;  while( *s != 0 )
         Value = Value*10 + ( *(s++) - '0' );  return Value;
    }
      

  4.   

    int StrToInt(char *s)
    {
      int  Value=0;
      while( *s != 0 )
         Value = Value*10 + ( *(s++) - '0' );
      return Value;
    }
      

  5.   

    atoi() ,atof() 分别是将字符串转化为整型和浮点型