[ad_1]
” I am trying to scan a user input (ascii character) as an integer, and show the ascii code for the entered character”
What you should do is exact opposite. You should read a character and display it as an integer, i.e.:
char c;
scanf("%c", &c); // <-- read character
printf("%d", c); // <-- display its integral value
input: a
, output: 97
Also note that while(character != 999)
isn’t very lucky choice for a terminating condition of your loop. Checking the return value of scanf
to determine whether the reading of character was successful might be more reasonable here:
while (scanf("%c", &character)) {
printf("ascii: %d\n", character);
}
[ad_2]