Formatted Printing

printf and sprintf format a list of values according to a format string that may use the following conversions:

%%

A percent sign.

%b

An unsigned integer (binary).

%c

The character corresponding to the ordinal value.

%d

A signed integer.

%e

A floating-point number (scientific notation).

%f

A floating-point number (fixed decimal notation).

%g

A floating-point number (%e or %f notation).

%i

A synonym for %d.

%n

The number of characters formatted so far is stored into the corresponding variable in the parameter list.

%o

An unsigned integer (octal).

%p

A pointer (address in hexadecimal).

%s

A string.

%u

An unsigned integer (decimal).

%x

An unsigned integer (hexadecimal).

%B

Like %b, but using an uppercase B.

%D

An obsolete synonym for %ld.

%E

Like %e, but using an uppercase E.

%F

An obsolete synonym for %f.

%G

Like %g, but with an uppercase E (if applicable).

%O

An obsolete synonym for %lo.

%U

An obsolete synonym for %lu.

%X

Like %x, but using uppercase letters.

The following flags can be put between the % and the conversion letter:

space

Prefix a positive number with a space.

+

Prefix a positive number with a plus sign.

-

Left-align within the field.

0

Use zeros instead of spaces to right-align.

#

With o, b, x, and X: prefix a nonzero number with 0, 0b, 0x, or 0X.

number

Minimum field width.

.number

For a floating-point number, the number of digits after the decimal point. For a string, the maximum length. For an integer, the minimum width. The integer will be right-aligned, padded with zeros.

h

Interpret integer as C type short or unsigned short.

hh

Interpret integer as C type char.

j

Interpret integer as C99 type intmax_t.

l

Interpret integer as C type long or unsigned long.

ll, L, q

Interpret integer as C type quad (64-bit).

t

Interpret integer as C type ptrdiff_t.

v

Print string as series of ordinals. Use with d, o, b, x, or X.

V

Interpret integer according to Perl’s type.

z

Interpret integer as C type size_t.

An asterisk (*) may be used instead of a number; the value of the next item in the list will be used. With %*v, the next item in the list will be used to separate the values.

Parameter ordering can be obtained by inserting n$ directly after a % or *. This conversion will then use the nth argument.

See the section Formats below for an alternative way to obtain formatted output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset