2015-03-31 46 views
0

它们的等效字符我怎么能打印字符对于给定的ASCII码值?..打印的ASCII码值,并用C

我看到这个question,我的问题是相似的,只是相反

下面是我的程序,但它不起作用。

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;} 
+0

只要你知道,你可能不会使用ASCII。输入161,你可能会得到一些东西,也许。如果您使用的是ASCII,那将是一个错误,因为ASCII有128个编码点,编号为0到127。 – 2015-03-31 16:17:21

回答

2

在你的代码,你必须改变你的printf语句

printf(" %c is cherechter that have %d ASCII code\n", &ch ,&code); 

printf(" %c is cherechter that have %d ASCII code\n", ch ,code); 

因为,打印,你并不需要提供地址的变量。变量名称就够了。

0

更改您的代码:

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;}