scanf Type Field Characters
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
The following information applies to any of the
scanf family of functions, including the secure versions, such as
type character is the only required format field; it appears after any optional format fields. The
type character determines whether the associated argument is interpreted as a character, string, or number.
|Character||Type of input expected||Type of argument||Size argument in secure version?|
|Character. When used with ||Pointer to ||Required. Size does not include space for a null terminator.|
|Opposite size character. When used with ||Pointer to ||Required. Size argument does not include space for a null terminator.|
|Decimal integer.||Pointer to ||No.|
|An integer. Hexadecimal if the input string begins with "0x" or "0X", octal if the string begins with "0", otherwise decimal.||Pointer to ||No.|
|Octal integer.||Pointer to ||No.|
|A pointer address in hexadecimal digits. The maximum number of digits read depends on the size of a pointer (32 or 64 bits), which depends on the machine architecture. "0x" or "0X" are accepted as prefixes.||Pointer to ||No.|
|Unsigned decimal integer.||Pointer to ||No.|
|Hexadecimal integer.||Pointer to ||No.|
|Floating-point value consisting of optional sign (+ or –), series of one or more decimal digits containing decimal point, and optional exponent ("e" or "E") followed by an optionally signed integer value.||Pointer to ||No.|
|No input read from stream or buffer.||Pointer to ||No.|
|String, up to first white-space character (space, tab or newline). To read strings not delimited by space characters, use set of square brackets (||When used with ||Required. Size includes space for a null terminator.|
|Opposite-size character string, up to first white-space character (space, tab or newline). To read strings not delimited by space characters, use set of square brackets (||When used with ||Required. Size includes space for a null terminator.|
A specifiers (see printf Type Field Characters) are not available with
The size arguments, if required, should be passed in the parameter list immediately following the argument they apply to. For example, the following code:
char string1, string2; scanf_s("%10s %8s", string1, 11, string2, 9);
reads a string with a maximum length of 10 into
string1, and a string with a maximum length of 8 into
string2. The buffer sizes should be at least one more than the width specifications since space must be reserved for the null terminator.
The format string can handle single-byte or wide character input regardless of whether the single-byte character or wide-character version of the function is used. Thus, to read single-byte or wide characters with
scanf functions and
wscanf functions, use format specifiers as follows.
|To read character as||Use this function||With these format specifiers|
To scan strings with
scanf functions, and
wscanf functions, use the above table with format type-specifiers
S instead of