scanf Format Specifiers
Go Up to scanf, wscanf
In scanf format strings, format specifiers have the following form:
% [*] [width] [F|N] [h|l|L] type_char
Each format specifier begins with the percent character (%).
After the % come the following, in this order:
Component | Optional/Required | What It Is/Does | |
---|---|---|---|
[*] |
(Optional) |
Precision character. The precision character is an asterisk (*), not to be confused with the C indirection (pointer) operator. If the asterisk follows the percent sign (%) in a format specifier, the next input field will be scanned but it won't be assigned to the next address argument. The suppressed input data is assumed to be of the type specified by the type character that follows the asterisk character. | |
[width] |
(Optional) |
Width specifier. The width specifier (n), a decimal integer, controls the maximum number of characters to be read from the current input field. Up to n characters are read, converted, and stored in the current address argument. If the input field contains fewer than n characters, the ...scanf function reads all the characters in the field, then proceeds with the next field and format specifier. The success of literal matches and suppressed assignments is not directly determinable. If the ...scanf function encounters a whitespace or nonconvertible character before it reads "width" characters, it:
A non-convertible character is one that cannot be converted according to the given format (8 or 9 when the format is octal, J or K when the format is hexadecimal or decimal, and so on). |
|
[F|N] |
(Optional) |
Pointer size modifier. Overrides default size of address argument:
| |
[h|l|L] |
(Optional) |
Argument-type modifier. Overrides default type of address argument:
| |
type_char |
(Required) |