this is my code:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j;
char str[33];
printf ("Enter a character: ");
scanf ("%2c",&j);
flushall();
itoa (j, str, 16);
printf ("hexadecima l: %s\n", str);
getchar();
getchar();
return 0;
}
Q:
After I enter say 'N1', it will scan my ascii character and put it into address of i. Note that the hex value for character N1 is 4E31.However, when I use itoa, it output the hex value as 314E. Seemed that it reads the last memory and move backward. How do I overcome this problem? It's C language.
Thanks
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int j;
char str[33];
printf ("Enter a character: ");
scanf ("%2c",&j);
flushall();
itoa (j, str, 16);
printf ("hexadecima l: %s\n", str);
getchar();
getchar();
return 0;
}
Q:
After I enter say 'N1', it will scan my ascii character and put it into address of i. Note that the hex value for character N1 is 4E31.However, when I use itoa, it output the hex value as 314E. Seemed that it reads the last memory and move backward. How do I overcome this problem? It's C language.
Thanks
Comment