从char转换为int [英] Conversion from char to int
本文介绍了从char转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨大家好,我想写一个用for循环将所有字符转换为int的节目,我不知道在我的char变量中放入什么作为第一个值
我尝试过:
Hi Guys , i want to write a pogramme that convert all chars to int with a for loop , i don't know what to put in my char variable as a first value
What I have tried:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
char c ;
c =
system("color a ");
for(i=0;i<=255;i++)
{
printf("%c to int is : %d",c,c);
printf("\n");
}
return 0;
}
推荐答案
更改循环:
Change your loop:
int main()
{
unsigned char c;
for(c = 0; c != 255; c++)
{
printf("%c to int is : %d\n", c, (int) c);
}
return 0;
}
这篇关于从char转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文