In Chapter 19, Exploring Formatted Output, we exhaustively explored the printf() output specifiers using a variety of programs to demonstrate how these specifiers work. We can reuse much of that knowledge for input specifiers.
The input specifiers for scanf() are similar in syntax and meaning to the output specifiers of printf(), except for a few differences. Therefore, it is best to consider the format string specifiers for printf() and scanf() as only vaguely similar; do not rely on the documentation for one as a guide for the other.
The following differences should be noted:
- printf() accepts precision specification, while scanf() does not.
- printf() accepts the -, +, <space>, 0, and # flag specifiers, while scanf() does not.
Note that the input strings may have the -, +, and/or # characters and scanf() will interpret them as flags; however, these cannot be specified in the format specifier...