*** Welcome to piglix ***

Scanf format string


Scanf format string (which stands for "scan formatted") refers to a control parameter used by a class of functions in the string-processing libraries of various programming languages. The format string specifies a method for reading a string into an arbitrary number of varied data type parameter(s). The input string is by default read from the standard input, but variants exist that read the input from other sources.

The term "scanf" is due to the C language, which popularized this type of function, but these functions predate C, and other names are used, such as "readf" in ALGOL 68. Scanf format strings, which provide formatted input (parsing), are complementary to printf format strings, which provide formatted output (templating). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible parsers or template engines, but are sufficient for many purposes.

Mike Lesk's portable input/output library, including scanf, officially became part of Unix in Version 7.

The scanf function, which is found in C, reads input for numbers and other datatypes from standard input (often a command line interface or similar kind of a text user interface).

The following shows code in C that reads a variable number of unformatted decimal integers from the console and prints out each of them on a separate line:

After being processed by the program above, a messy list of integers such as

will appear neatly as:


...
Wikipedia

...