Formatted I/O: printfand scanf 349
Ta b le 16.1 printfFlags
Flag Meaning
- Left-justify value
- Precede value with +or -
(space) Precede positive value with space character
0 Zero fill numbersPrecede octal value with 0 , hexadecimal value with 0x(or 0X); display decimal
point for floats; leave trailing zeroes for gor Gformat
Ta b le 16.2 printfWidth and Precision Modifiers
Specifier Meaning
number Minimum size of field
* Ta ke next argument to printfas size of field
.number Minimum number of digits to display for integers; number of decimal
places for eor fformats; maximum number of significant digits to display
for g; maximum number of characters for sformat
.* Ta ke next argument to printfas precision (and interpret as indicated in
preceding row)
Ta b le 16.3 printfType Modifiers
Type Meaning
hh Display integer argument as a character
h* Display short integer
l* Display long integer
ll* Display long long integer
L Display long double
j* Display intmax_tor uintmax_tvalue
t* Display ptrdiff_tvalue
z* Display size_tvalue
*Note:These modifiers can also be placed in front of the nconversion character to
indicate the corresponding pointer argument is of the specified type.
Ta b le 16.4 lists the conversion characters that can be specified in the format string.