I have a char array composed of hex values that looks similar to this:
char str[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff";
After manipulating this string, I want to fprintf this string to a file using this statement:
fprintf(fp, "%X\n", str);
but I'm getting an output similar to this:
65C58A20
Seems like it got condensed to a single hex number. How can I fprintf the str in the same form I declared it above, with separate hex values for each individual byte?
sprintf()work? Use it to convert the char array to a string, then print out that string to file instead?%X?! Did you read the manual forprintf?fprintf(fp, "%02X\n", (unsigned char)str[index]);"\x80\xe8\xdc\xff\xff\xff-->"\x80\xe8\xdc\xff\xff\xff";(add last 2 characters, if that is what you meant.