To display char in hexadecimal format, you just need the correct format specifier, and you need to go through the buffer:
//where n is bytes back from the read: printf("Here is the message(size %d): ", n); for(int i = 0; i<n; i++) printf("%x", buffer[i]);
The code you used printed the address of the buffer, so it did not change.
Since it took you some time if you want each byte to be nicely formatted with 0xNN , you can also use the %#x format:
for(int i = 0; i<n; i++) printf("%#x ", buffer[i]);
To get something like:
0x10 0x4 0x44 0x52...
source share