Using internal data conversion
It should be fairly obvious that the ability of printf()
to convert binary values into strings and of scanf()
to convert strings into binary values is very powerful. These facilities are not constrained to console streams, nor are they constrained to file streams. Whenever we need to carry out internal data conversions, we have the same facilities available to us with the related sprintf()
and sscanf()
functions. Rather than use streams, these functions use strings—arrays of characters—as their initial input and our resultant output.
We have seen how scanf()
can be finicky. One way to mitigate irregular or troublesome input is to read that input into a large string buffer and then process that string buffer in various ways with sscanf()
.
The function prototypes for sprintf()
and scanf()
look like this:
int sprintf( char* buffer , const...