Go to the previous, next section.

Numeric Input Conversions

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 section 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 section 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 section 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 section 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:

`h'
Specifies that the argument is a short int * or unsigned short int *.

`l'
Specifies that the argument is a long int * or unsigned long int *.

`L'
Specifies that the argument is a 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.)

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 section 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:

`l'
Specifies that the argument is of type double *.

`L'
Specifies that the argument is of type long double *.

Go to the previous, next section.