The scanf Format String

From RAD Studio
Jump to: navigation, search

Go Up to scanf, wscanf


The format string controls how each ...scanf function scans, converts, and stores its input fields.

The format string is a character string that contains three types of objects:

  • Whitespace characters
  • Non-whitespace characters
  • Format specifiers

Whitespace Characters

The whitespace characters are blank, tab (\t), or newline (\n).

If a ...scanf function encounters a whitespace character in the format string, it reads, but does not store, all consecutive whitespace characters up to the next non-whitespace character in the input.

Trailing whitespace is left unread (including a newline), unless explicitly matched in the format string.

Non-whitespace Characters

The non-whitespace characters are all other ASCII characters except the percent sign (%).

If a ...scanf function encounters a non-whitespace character in the format string, it will read, but not store, a matching non-whitespace character.

Format Specifiers

The format specifiers direct the ......scanf functions to read and convert characters from the input field into specific types of values, then store them in the locations given by the address arguments.

Note: Each format specifier must have an address argument. If there are more format specs than addresses, the results are unpredictable and likely disastrous.

Excess address arguments (more than required by the format) are ignored.

See Also