函数原型为:
int atoi(const char *str)
函数的功能为:把参数 str 所指向的字符串转换为一个 int 整型。
参数:str 要转换为整数的字符串
返回值:返回转换后的长整数,如果没有执行有效转换,则返回 0.
例子:
#include <stdio.h>#include <stdlib.h>#include <string.h>int main() {char str1[] = "33333";int val1 = atoi(str1);printf("字符串值 = %s, 整型值 = %d\n", str1, val1);char str2[] = "hello";int val2 = atoi(str2);printf("字符串值 = %s, 整型值 = %d\n", str2, val2);system("pause");return 0;}
输出为:

