Chapter 21: Exploring Formatted Input
Using console command-line arguments to get string input into our running programs is often handy, but not very useful if we want to read lots of values of any data type while our program is running. To do that, we need to explore how to use formatted input. Formatted input is the opposite end of the pipe, so to speak, to formatted output. Just as we can use formatted output with print()
, various value formats can be easily read to the console by using scanf()
. Both of these functions do the heavy lifting of converting values into desired output strings or, conversely, converting input character strings into desired values.
To understand input formatting, we will need to first understand the concept of streams. We will then use the technique of experimentation—or, more specifically, trial and observation—to discover and verify our understanding of how C input streams operate. We will later expand...