I have a buffer of raw values, say, void* buffer
or better, char* buffer
- a raw byte stream, for example, read from a file. I'd like the bytes in the buffer to be represented and displayed in several ways, for example, as a float
, or as a long long
in runtime. I'd ask a user for desired format string, for example, %10d
, and pass the format string to printf()
. However, there are no format specifiers in printf()
so it would expect an untyped (or byte-stream) buffer as a second argument?
How can I tell printf()
to get the expected data from the buffer and display it according to the given format string? I won't like to use switch-case
or if-then
trees.