Character to Ascii
Hello there, I'm stuck trying to convert any scanned character to ascii. I know that printf("%d", a); will print the value of the letter a (that is 74 or 75), but i can't get to save it.
This is where I'm at
but that doesn't seem to work.
print("enter a letter\n");
x = (int)letter;
any input is highly appreciated,
Change scanf("&c", letter); to
are you sure the ASCII value of a is 74 or 75? this code prints 97.
printf("enter a letter\n");
He may be talking hex, but I think that's in and around the 60's ...
I believe a is 0x61 in hex.
yeah sorry. it's 97. I think 74 was for 'A'. but yeah I did have that code..
I just can't figure out how to save what's being printed as an integer x or (in the case of scanning a, x should be set to 97).
thanks for the quick replies too.
The character has an integer value.
char letter = 'a';
printf("letter = '%c' (using %%c)\n", letter);
printf("letter = %d (using %%d)\n", letter);
printf("letter = %#x (using %%x)\n", letter);
/* my output
letter = 'a' (using %c)
letter = 97 (using %d)
letter = 0x61 (using %x)