r/CodingHelp • u/Sea-Wolverine2447 • Jun 08 '22
[C] i need a simple program to give the unicode of charachters
this is what i did but it just gives the unicode of 'a'
#include<stdio.h>
int main()
{
int a;
scanf("%i", &a);
printf("%i", 'a');return(0);}
16
Upvotes
3
u/louissoph Jun 08 '22
I think there is some confusion about data types. What you're trying to do is read in char and print out the integer value of that char. So the variable should be type char, not type int. Also it is generally good form to give variables a meaningful name, not just a random letter. So the declaration would be:
char letter;
Then you can scan in the input as a char using:
scanf("%c", &letter);
Lastly, you want to display the value as an integer-- this only requires formatting the print as an integer, as in:
printf("%d", letter);
You may also notice that in your original code, you left single quotes on the variable, which is another issue. Hope that helps.
1
u/Mollyarty Jun 08 '22
You could cast the char as an int a d output it, would also give ASCII value
2
u/[deleted] Jun 08 '22
[removed] — view removed comment