I have a binary file I would like to include in my C source code (temporarily, for testing purposes) so I would like to obtain the file contents as a C string, something like this:
\x01\x02\x03\x04
Is this possible, perhaps by using the od
or hexdump
utilities? While not necessary, if the string can wrap to the next line every 16 input bytes, and include double-quotes at the start and end of each line, that would be even nicer!
I am aware that the string will have embedded nulls (\x00
) so I will need to specify the length of the string in the code, to prevent these bytes from terminating the string early.