When ...scanf Stops Scanning

From RAD Studio
Jump to: navigation, search

Go Up to scanf, wscanf

A ...scanf function might stop scanning a particular input field before reaching the normal field-end character (whitespace), or it might terminate entirely.

Stop and Skip to Next Input Field

The various ...scanf functions stop scanning and storing the current input field and proceed to the next one if any of the following occurs:

  • A precision character (*) appears after the % in the format specifier. The current input field is scanned but not stored.
  • width characters have been read.
  • The next character read cannot be converted under the current format (for example, an A when the format is decimal).
  • The next character in the input field does not appear in the search set (or does appear in an inverted search set).

When scanf stops scanning the current input field for one of these reasons, it assumes that the next character is unread and is either:

  • The first character of the following input field, or
  • The first character in a subsequent read operation on the input.


...scanf functions will terminate under the following circumstances:

  • The next character in the input field conflicts with a corresponding non-whitespace character in the format string.
  • The next character in the input field is EOF.
  • The format string has been exhausted.

If a character sequence that is not part of a format specifier occurs in the format string, it must match the current sequence of characters in the input field.

......scanf functions will scan but not store the matched characters.

When a conflicting character occurs, it remains in the input field as if the ...scanf function never read it.

See Also