I know C++ very well, but then I decided to try and learn a little C since it is compatible with Unix. I tried to write a fairly simple program that will convert the number you enter into Hexadecimal. Here is my code:
#include <stdio.h>
main()
{
int ch;
printf("Type in a number to be converted:\n");
ch=getc(stdin);
printf("The value %d converted to Hex is: %x\n",ch,ch);
return 0;
}
Output:
Type in a number to be converted:
7
The value 31 converted to Hex is: 37
Or something like that, the numbers are completely diff. then what they should be.
the last output line should say:
"The value 7 converted to Hex is: 7"
Please let me know what is wrong with my code.