printf - Write formatted output

Synopsis

printf format [ argument ... ]

Description

You can use printf to format and display output on standard output. The syntax is similar to the ILE C printf() function. printf formats using the following conversion control string syntax:

%[flags][width].[precision]conversion

conversion specifies how the corresponding argument is displayed. You must specify one of the following conversion characters:

c
Unsigned character.
d
Signed decimal number.
e,E
Scientific notation.
f
Floating point number.
g,G
Scientific notation with significant digits.
i
Signed decimal number.
o
Unsigned octal number.
s
String.
u
Unsigned decimal number.
x
Unsigned hexadecimal number with digits 0123456789abcdef.
X
Unsigned hexadecimal number with digits 0123456789ABCDEF.

flags control how the argument is displayed in the following ways:

- (minus)
Left align argument within the field.
+ (plus)
Prefix all numbers with a + or -.
space
Prefix positive numbers with <space> and negative numbers with -.
0
Pad field width with leading zeros for d, e, E, f, g, or G.
#
Use an alternate output form depending on conversion character. For o, prefix octal numbers with "0". For x, prefix hexadecimal numbers with "0x". For X, prefix hexadecimal numbers with "0X". For e, E, f, g, or G, display decimal point. For g or G, display trailing zeros.

width is the minimum number of character positions displayed. Using an asterisk (*) character for the width means the value of the next argument is the field width.

The meaning of precision depends on the conversion character.

  • For d, i, o, u, x, or X precision specifies the minimum number of digits to be displayed.
  • For e, E, or f precision specifies the number of digits to be displayed after the decimal point.
  • For g, or G precision specifies the maximum number of significant digits.
  • For s precision specifies the maximum number of characters to be displayed.

Options

None.

Operands

Each argument is converted and displayed as specified by the format.

Exit status

  • 0 when successful.
  • >0 when unsuccessful.