written inCSDN
int atoi( const char * str );
e.g:
#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");
}
}
notice:
1.The function stops reading the input string at the first character that it cannot recognize as part of a number. This character may be the null character ('/0' or L'/0') terminating the string
2.The str argument to atoi and _wtoi has the following form:
[ whitespace ] [ sign ] [ digits ]]
A whitespace consists of space or tab characters, which are ignored; sign is either plus (+) or minus (–); and digits are one or more digits.
int atoi( const char * str );
e.g:
#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");
}
}
notice:
1.The function stops reading the input string at the first character that it cannot recognize as part of a number. This character may be the null character ('/0' or L'/0') terminating the string
2.The str argument to atoi and _wtoi has the following form:
[ whitespace ] [ sign ] [ digits ]]
A whitespace consists of space or tab characters, which are ignored; sign is either plus (+) or minus (–); and digits are one or more digits.