The reason it doesn't print anything is that the first byte is null, which printf("%s")
considers to mean "end of string". And if there had been no null bytes in the data, printf
wouldn't have known where to stop, causing an overrun.
What you have in tmp
is not a C string, just an array of 4 bytes. You can print them with something like this:
printf("%02x %02x %02x %02x", tmp[0], tmp[1], tmp[2], tmp[3]);
%x
is the format specifier for hexadecimal integers, 2
is the field length and 0
means that the value should be zero-prefixed if it's shorter that the field length, i.e. the value 1
should be printed as 01
etc.