你定义的str[1000]就是假定程序可以转换出1000位的整数嘛,不然弄那么大干什么。
授人以渔,不授人以鱼。
// crt_atoi.c // This program shows how numbers // stored as strings can be converted to // numeric values using the atoi functions. #include <stdlib.h> #include <stdio.h> #include <errno.h> int main( void ) { char *str = NULL; int value = 0; // An example of the atoi function. str = " -2309 "; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function. str = "31412764"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function // with an overflow condition occuring. str = "3336402735171707160320"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); if (errno == ERANGE) { printf("Overflow condition occurred.\n"); } }