Input Validation
In practice, program users don't always follow instructions, and you can get a mismatch between what a program expects as input and what it actually gets. Such conditions can cause a program to fail. However, often you can anticipate likely input errors, and, with some extra programming effort, have a program detect and work around them.
Suppose, for example, that you're writing a program that prompts the user to a non-negative integer. Another kind of error is to enter values that are not valid for the particular task the program is doing.
Suppose, for instance, that you had a loop that processes non-negative numbers. One kind of error the user can make is to enter a negative number. You can use a relational expression to test ...
Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.