How do you convert the ASCII characters to their hexadecimal values?
Such as 'A' is equal 65.
ssprint and sscanf only can convert ints to hexdecimals. And atoi is not a standard C function.
I'm stuck.
How do you convert the ASCII characters to their hexadecimal values?
Such as 'A' is equal 65.
ssprint and sscanf only can convert ints to hexdecimals. And atoi is not a standard C function.
I'm stuck.
Cast the char to an int before using sprintf()
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Code:#include <stdio.h> int main (void) { char ch = 'A'; printf("ch = '%c'\n", ch); printf("ch = %d\n", (int)ch); printf("ch = 0x%x\n", (unsigned int)ch); printf("ch = 0%o\n", (unsigned int)ch); return (0); } /* my output ch = 'A' ch = 65 ch = 0x41 ch = 0101 */
>ssprint and sscanf only can convert ints to hexdecimals.
A char is an integral value, in fact, char and int are often used interchangeably in C. Just use the %x format for sprintf and cast the char as unsigned.
>And atoi is not a standard C function.
Yes it is. I believe you are thinking of itoa, which is not a standard function.
-Prelude
My best code is written with the delete key.