version 1.9, 2000/03/06 03:15:59 |
version 1.10, 2000/03/10 20:17:49 |
|
|
.\" $OpenBSD$ |
.\" $OpenBSD$ |
|
.\" |
.\" Copyright (c) 1989, 1990 The Regents of the University of California. |
.\" Copyright (c) 1989, 1990 The Regents of the University of California. |
.\" All rights reserved. |
.\" All rights reserved. |
.\" |
.\" |
|
|
.Nm printf |
.Nm printf |
formats and prints its arguments, after the first, under control |
formats and prints its arguments, after the first, under control |
of the |
of the |
.Ar format . |
.Ar format . |
The |
The |
.Ar format |
.Ar format |
is a character string which contains three types of objects: plain characters, |
is a character string which contains three types of objects: plain characters, |
which are simply copied to standard output, character escape sequences which |
which are simply copied to standard output, character escape sequences which |
are converted and copied to the standard output, and format specifications, |
are converted and copied to the standard output, and format specifications, |
each of which causes printing of the next successive |
each of which causes printing of the next successive |
.Ar argument . |
.Ar argument . |
.Pp |
.Pp |
The |
The |
.Ar arguments |
.Ar arguments |
|
|
or |
or |
.Cm s ; |
.Cm s ; |
otherwise it is evaluated as a C constant, with the following extensions: |
otherwise it is evaluated as a C constant, with the following extensions: |
.Pp |
.Bl -bullet -offset indent |
.Bl -bullet -offset indent -compact |
|
.It |
.It |
A leading plus or minus sign is allowed. |
A leading plus or minus sign is allowed. |
.It |
.It |
|
|
.El |
.El |
.Pp |
.Pp |
The format string is reused as often as necessary to satisfy the |
The format string is reused as often as necessary to satisfy the |
.Ar arguments . |
.Ar arguments . |
Any extra format specifications are evaluated with zero or the null |
Any extra format specifications are evaluated with zero or the null |
string. |
string. |
.Pp |
.Pp |
Character escape sequences are in backslash notation as defined in |
Character escape sequences are in backslash notation as defined in |
.St -ansiC . |
.St -ansiC . |
The characters and their meanings |
The characters and their meanings are as follows: |
are as follows: |
.Pp |
.Bl -tag -width Ds -offset indent |
.Bl -tag -width Ds -offset indent -compact |
.It Cm \ee |
.It Cm \ee |
Write an <escape> character. |
Write an <escape> character. |
.It Cm \ea |
.It Cm \ea |
|
|
Each format specification is introduced by the percent |
Each format specification is introduced by the percent |
.Pq Sq \&% |
.Pq Sq \&% |
character. |
character. |
The remainder of the format specification includes, |
The remainder of the format specifiers include, |
in the following order: |
in the following order: |
.Bl -tag -width Ds |
.Bl -tag -width Ds |
.It "Zero or more of the following flags:" |
.It "Zero or more of the following flags:" |
|
|
Specifies that the value should be printed in an |
Specifies that the value should be printed in an |
.Dq alternate form . |
.Dq alternate form . |
For the |
For the |
.Cm c , |
.Cm c , |
.Cm d , |
.Cm d , |
and |
and |
.Cm s |
.Cm s |
formats, this option has no effect. For the |
formats, this option has no effect. |
|
For the |
.Cm o |
.Cm o |
format the precision of the number is increased to force the first |
format the precision of the number is increased to force the first |
character of the output string to a zero. For the |
character of the output string to a zero. |
|
For the |
.Cm x |
.Cm x |
.Pq Cm X |
.Pq Cm X |
format, a non-zero result has the string |
format, a non-zero result has the string |
.Li 0x |
.Li 0x |
.Pq Li 0X |
.Pq Li 0X |
prepended to it. For |
prepended to it. |
.Cm e , |
For |
|
.Cm e , |
.Cm E , |
.Cm E , |
.Cm f , |
.Cm f , |
.Cm g , |
.Cm g , |
and |
and |
.Cm G |
.Cm G |
formats, the result will always contain a decimal point, even if no |
formats, the result will always contain a decimal point, even if no |
digits follow the point (normally, a decimal point only appears in the |
digits follow the point (normally, a decimal point only appears in the |
results of those formats if a digit follows the decimal point). For |
results of those formats if a digit follows the decimal point). |
|
For |
.Cm g |
.Cm g |
and |
and |
.Cm G |
.Cm G |
|
|
a sign placed before the number when using signed formats. |
a sign placed before the number when using signed formats. |
.It Sq \&\ \& |
.It Sq \&\ \& |
A space specifies that a blank should be left before a positive number |
A space specifies that a blank should be left before a positive number |
for a signed format. A |
for a signed format. |
.Dq + |
A |
|
.Ql + |
overrides a space if both are used. |
overrides a space if both are used. |
.It Cm \&0 |
.It Cm \&0 |
A zero character specifies that zero-padding should be used |
A zero character specifies that zero-padding should be used |
rather than blank-padding. This flag is ignored if used with a precision |
rather than blank-padding. |
|
This flag is ignored if used with a precision |
specifier and any of the |
specifier and any of the |
.Cm d , i , o , u , |
.Cm d , i , o , u , |
or |
or |
.Cm x |
.Cm x |
.Pq Cm X |
.Pq Cm X |
formats. A |
formats. |
.Dq \&- |
A |
|
.Ql \&- |
overrides a |
overrides a |
.Dq \&0 |
.Ql \&0 |
if both are used. |
if both are used. |
.El |
.El |
.It "Field Width:" |
.It "Field Width:" |
|
|
.El |
.El |
.Pp |
.Pp |
A field width or precision may be |
A field width or precision may be |
.Dq \&* |
.Ql \&* |
instead of a digit string. |
instead of a digit string. |
In this case an |
In this case an |
.Ar argument |
.Ar argument |
|
|
the precision specification for the argument; when the precision is |
the precision specification for the argument; when the precision is |
missing, 6 digits are produced. |
missing, 6 digits are produced. |
An upper-case |
An upper-case |
.Dq E |
.Sq E |
is used for an |
is used for an |
.Cm E |
.Cm E |
format. |
format. |
|
|
precision is 0 or missing, all characters in the string are printed. |
precision is 0 or missing, all characters in the string are printed. |
.It Cm \&% |
.It Cm \&% |
Print a |
Print a |
.Dq \&% ; |
.Ql \&% ; |
no argument is used. |
no argument is used. |
.El |
.El |
.Pp |
.Pp |