Reputation: 53
So I have a memory block that is fill with hex values, and I want to read in those hex values as Ascii. Unfortunately, I can't seem to figure out how to do this.
char* charstring = malloc(sizeof(uint16_t));
uint8_t test = 0x65;
sprintf(charstring, "%x ", test);
fprintf(Output, "%s", charstring);
free(charstring);
This just gives me a ton of "65", not the "e" I was expecting. I know it's a simple question, but I've literally clicked every link on the front page of google and can't figure out my problem!
Upvotes: 0
Views: 162
Reputation: 122403
You get 65
because you are using %x
as the format specifier, change it to %c
for the character value.
Note that you don't have enough space for charstring
for the null terminator. Fix it.
Upvotes: 5