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

Formatted Input

In command-line programming, input comes from the keyboard, and the standard input and output library, stdio, gives the programmer an interface to that method of input in a formatted way.

The principle is similar to the printf function in that the input stream (be it the keyboard or a variable) is matched against the format string, and variables assign values according to the format specifiers encountered.

The two functions covered here—scanf and sscanf—mirror the printf and sprintf functions in that they work directly with the hardware and also with variables. In other words, the source data can come from the keyboard (via the operating system) or from a string that has to be broken into fields.

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