字符串转成整数

来源:互联网 发布:2016淘宝店申请步骤 编辑:程序博客网 时间:2024/06/04 20:01

 

int ascii_to_integer( char *string )
{
 int value;
 int digit;

 value = 0;

 /*
 ** Convert digits of the string one by one.
 */
 while( *string >= '0' && *string <= '9' ){
  value *= 10;
  value += *string - '0';
  string++;
 }

 /*
 ** Error check: if we stopped because of a nondigit, set the
 ** result to zero.
 */
 if( *string != '/0' )
  value = 0;

 return value;
}