This section describes the scanf
conversions for reading numeric values.
The `%d' conversion matches an optionally signed integer in decimal radix. The syntax that is recognized is the same as that for the strtol
function (see Parsing of Integers) with the value 10
for the base argument.
The `%i' conversion matches an optionally signed integer in any of the formats that the C language defines for specifying an integer constant. The syntax that is recognized is the same as that for the strtol
function (see Parsing of Integers) with the value 0
for the base argument. (You can print integers in this syntax with printf
by using the `#' flag character with the `%x', `%o', or `%d' conversion. See Integer Conversions.)
For example, any of the strings `10', `0xa', or `012' could be read in as integers under the `%i' conversion. Each of these specifies a number with decimal value 10
.
The `%o', `%u', and `%x' conversions match unsigned integers in octal, decimal, and hexadecimal radices, respectively. The syntax that is recognized is the same as that for the strtoul
function (see Parsing of Integers) with the appropriate value (8
, 10
, or 16
) for the base argument.
The `%X' conversion is identical to the `%x' conversion. They both permit either uppercase or lowercase letters to be used as digits.
The default type of the corresponding argument for the %d
and %i
conversions is int *
, and unsigned int *
for the other integer conversions. You can use the following type modifiers to specify other sizes of integer:
short int *
or unsigned short int *
.
long int *
or unsigned long int *
. Two `l' characters is like the `L' modifier, below.
long long int *
or unsigned long long int *
. (The long long
type is an extension supported by the GNU C compiler. For systems that don't provide extra-long integers, this is the same as long int
.)
The `q' modifier is another name for the same thing, which comes from 4.4 BSD; a long long int
is sometimes called a ``quad'' int
.
All of the `%e', `%f', `%g', `%E', and `%G' input conversions are interchangeable. They all match an optionally signed floating point number, in the same syntax as for the strtod
function (see Parsing of Floats).
For the floating-point input conversions, the default argument type is float *
. (This is different from the corresponding output conversions, where the default type is double
; remember that float
arguments to printf
are converted to double
by the default argument promotions, but float *
arguments are not promoted to double *
.) You can specify other sizes of float using these type modifiers:
double *
.
long double *
.