O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using scanf

The basic syntax of the scanf function is almost identical to the printf equivalent:

scanf (<format>, <target variables . . .> )

In this definition, <format> is again a format string containing the same format specifiers, except that only the basic % plus a character actually make any sense in this context. In other words, the scanf function is not really appropriate for use in cases where fields have to be laid out in a specific way on the screen.

If you were to use the scanf function to specify a field width, the input library is not sophisticated enough to stop allowing data entry once the field with has been reached. However, only the data that fits inside the field is used in the variable that the field maps to.

If the data ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required