atoi, _atoi_l, _wtoi, _wtoi_l

来源:互联网 发布:人民邮电 算法谜题 编辑:程序博客网 时间:2024/04/28 21:25

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

Function: atoi( "  -2309 " ) = -2309Function: atoi( "31412764" ) = 31412764Function: atoi( "3336402735171707160320" ) = 2147483647Overflow condition occurred.

 

原创粉丝点击