[英]Printing ASCII-code values and their equivalent chars in C
How could I print char for given ASCII code value?.. 如何为给定的ASCII码值打印char?
I saw this question , my problem is similar, just contrary 我看到这个问题 ,我的问题是相似的,恰恰相反
Below is my program, but it doesn't work. 下面是我的程序,但是它不起作用。
int main (){
int code; // code that user enters
char ch; //"codes" related ASCII charcter
printf("Enter a ASCII code value: \n");
scanf("%d", &code);
ch=code;
printf(" %c is cherechter that have %d ASCII code\n", &ch ,&code);
system("PAUSE");
return 0;}
In your code, you have to change your printf statement 在您的代码中,您必须更改您的printf语句
printf(" %c is cherechter that have %d ASCII code\n", &ch ,&code);
to 至
printf(" %c is cherechter that have %d ASCII code\n", ch ,code);
because, to print the values , you don't need to supply the address of the variables. 因为,要打印值 ,您无需提供变量的地址 。 The variable name is enough. 变量名就足够了。
Change your code to: 将您的代码更改为:
int main (){
char code; //change from int to char
char ch;
printf("Enter a ASCII code value: \n");
scanf("%c", &code);//ASCII is a character not integer
ch=code;
printf(" %c is cherechter that have %x and %d ASCII code\n", ch ,code,code);//don't print the address access the value
system("PAUSE");
return 0;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.