I am trying to create a program where when I enter a character, after the user presses enter it displays the hexadecimal of it. I am seeming to have problems finding how to do it. Any suggestions? Thanks
Printable View
I am trying to create a program where when I enter a character, after the user presses enter it displays the hexadecimal of it. I am seeming to have problems finding how to do it. Any suggestions? Thanks
Something like this?
That's the easy way. If you want to write a function like toHex() that's a whole different ballgame.Code:#include <stdio.h>
int main()
{
char c = 10;
printf("%x\n", c);
return 0;
}
edit: maybe you are having problems with the input as well?
Code:char c;
scanf("%c", &c);
Is that what the %x does?? Converts it into a hexadecimal. Here is what I have so far..
Code:#include <stdio.h>
main()
{ char c[5];
puts("Enter Character:");
while(gets(c) != NULL)
{ puts(c);
printf("\n");
}
}
%x is just another format specifier like %d, %f etc.it is used for hexadecimal numbers.it gives the hexadecimal form of the corresponding argument.
for eg.
will output FCode:int i=15;
printf("%x",i);
Similarly %o is used for octal.