C语言 如何将字符数组 转换为整数

char s110="123";

如何将这个字符数组转换为整数123;

请教各位大手子了!

直接用atoi这个调用函数,形式为int a=atoi(字符数组);要加头文件的#include<sting.h>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-21
atoi() 字符串转换为整形
atol() 字符串转换为长整形
atof()字符串转换为浮点型
第2个回答  推荐于2017-09-01
#include <iostream>
using namespace std;
int main()
{
char *a="123";
cout<<atoi(a);
return 0;
}
第3个回答  推荐于2017-09-30
#include <iostream>
using namespace std;
int main()
{
char *a="123";
cout<<atoi(a);
return 0;
}追问

另外,我想再转回来,应该如何去转呢! int 转换为 char单个字符!

追答

#include
using namespace std;

int main()
{
int i=123;
char a[10]={'\0'};
itoa(i,a,10);
cout<<a;
return 0;
}

本回答被提问者和网友采纳
第4个回答  2012-08-21
char strNum[5] = "123";
char strNum2[5] = {0};
int num = 0;
num = atoi(strNum);
sprintf(strNum2, "%d", num);
相似回答