c/c++ atoi把字符转整形int类型
#include <stdlib.h>
#include <stdio.h>
int main()
{
char str1[] = "123";
char str2[] = "-456";
char str3[] = "0xABC";
int num1 = atoi(str1);
int num2 = atoi(str2);
int num3 = atoi(str3);
printf("%d, %d, %d\n", num1, num2, num3);
return 0;
}
运行结果:123, -456, 0