0

How could I print char for given ASCII code value?..

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;}  
Community
  • 1
  • 1
pan91
  • 25
  • 3
  • Just so you know, you are probably not using ASCII. Enter 161, you'll probably get something, maybe ¡. If you were using ASCII, that would be an error because ASCII has 128 codepoints numbered 0 to 127. – Tom Blodget Mar 31 '15 at 16:17

2 Answers2

2

In your code, you have to change your printf statement

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.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

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;}  
Nerdy
  • 1,016
  • 2
  • 11
  • 27