vim 7.3
gcc 版本 : 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
system : Fedora 14
- /**
- * 将数字字符串转换为整数
- */
- #include <stdio.h>
- #include <ctype.h>
- int ascii_to_integer( char * string );
- int main()
- {
- char str[] = "123456";
- int result ;
- result = ascii_to_integer(str);
- printf("%d\n",result);
- return 1;
- }
- int ascii_to_integer( char * string )
- {
- int number = 0 ;
- while( *string >= '0' && *string <= '9' ){
- number *= 10;
- number += *string - '0';
- string++;
- }
- if( *string != '\0'){
- number = 0;
- }
- return number;
- }