printf.1 (2010 09)

p
printf(1) printf(1)
NAME
printf - format and print arguments
SYNOPSIS
printf format [ arg ... ]
DESCRIPTION
printf writes formatted arguments to the standard output. The arg arguments are formatted under
control of the format operand.
format is a character string patterned after the formatting conventions of
printf() (see printf (3S)),
and contains the following types of objects:
characters Characters that are not escape sequences or conversion specifications (as
described below) are copied to standard output.
escape sequences These are interpreted as non-graphic characters:
\a alert
\b backspace
\f form-feed
\n new-line
\r carriage return
\t tab
\v vertical tab
\’ single quote character
\\ backslash
\n the 8-bit character whose ASCII code is the 1-, 2-, 3-, or 4-digit octal
number n, whose first character must be a zero.
conversion specification
Specifies the output format of each argument (see below).
Arguments following format are interpreted as strings if the corresponding format is either
c or s;
otherwise they are treated as constants.
Conversion Specifications
Each conversion specification is introduced by the percent character
%. After the % character, the follow-
ing can appear in the sequence indicated:
flags Zero or more flags, in any order, which modify the meaning of the conversion
specification. The flag characters and their meanings are:
- The result of the conversion is left-justified within the field.
+ The result of a signed conversion always begins with a sign, + or -.
<space> If the first character of a signed conversion is not a sign, a space char-
acter is prefixed to the result. This means that if the space flag and
+
flag both appear, the space flag is ignored.
# The value is to be converted to an "alternate form". For c, d, i,
u, and
s conversions, this flag has no effect. For o conversion, it increases
the precision to force the first digit of the result to be a zero. For x or
X conversion, a non-zero result has 0x or 0X prefixed to it. For e, E,
f, g, and G conversions, the result always contains a radix character,
even if no digits follow the radix character. For g and G conversions,
trailing zeros are not removed from the result, contrary to usual
behavior.
field width An optional string of decimal digits to specify a minimum field width . For an output
field, if the converted value has fewer bytes than the field width, it is padded on the left
(or right, if the left-adjustment flag,
- has been given) to the field width.
precision The precision specifies the minimum number of digits to appear for the
d, o, i, u, x,or
X conversions (the field is padded with leading zeros), the number of digits to appear
after the radix character for the e and f conversions, the maximum number of
significant digits for the g conversion, or the maximum number of bytes to be printed
from a string in s conversion. The precision takes the form of a period . followed by a
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)