Key Concepts
C programs see input as a stream of incoming bytes. The getchar() function interprets each byte as being a character code. The scanf() function sees input the same way, but, guided by its conversion specifiers, it can convert character input to numeric values. Many operating systems provide redirection, which allows you to substitute a file for a keyboard for input and to substitute a file for a monitor for output.
Programs often expect a particular form of input. You can make a program much more robust and user-friendly by anticipating entry errors a user might make and enabling the program to cope with them.
With a small program, input validation might be the most involved part of the code. It also opens up many choices. For example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access