C语言中 字符串如何转为整型数值
背景:main(){charStr[]="19,2,30,67,5";intnum;num=a[2];printf("%d\n",a);//输出51printf("%s\...
背景:
main() {
char Str[] = "19,2,30,67,5";
int num;
num = a[2];
printf("%d\n", a );//输出51
printf("%s\n", a );//输出30
}
a[2]本来是30的(字符串),用%d输出则为51,怎么回事,应该怎么转换
若不将a[2]转为整型数值,就没办法用a[2]进行计算了,其他也一样
越简单越好
啊,忘了,要将char Str[] = "19,2,30,67,5";
改为char Str[] ={"19","2","30","67","5"}; 展开
main() {
char Str[] = "19,2,30,67,5";
int num;
num = a[2];
printf("%d\n", a );//输出51
printf("%s\n", a );//输出30
}
a[2]本来是30的(字符串),用%d输出则为51,怎么回事,应该怎么转换
若不将a[2]转为整型数值,就没办法用a[2]进行计算了,其他也一样
越简单越好
啊,忘了,要将char Str[] = "19,2,30,67,5";
改为char Str[] ={"19","2","30","67","5"}; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询