1 .\" @(#)printf.3s 6.3 (Berkeley) 6/5/86
3 .TH PRINTF 3 "June 5, 1986"
6 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf \- formatted output conversion
10 #include <sys/types.h>
14 int printf(const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
15 int fprintf(FILE *\fIstream\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
16 int sprintf(char *\fIs\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
17 int snprintf(char *\fIs\fP, size_t \fIn\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
18 int vprintf(const char *\fIformat\fP, va_list \fIargs\fP);
19 int vfprintf(FILE *\fIstream\fP, const char *\fIformat\fP, va_list \fIargs\fP);
20 int vsprintf(char *\fIs\fP, const char *\fIformat\fP, va_list \fIargs\fP);
21 int vsnprintf(char *\fIs\fP, size_t \fIn\fP, const char *\fIformat\fP, va_list \fIargs\fP);
26 places output on the standard output stream
29 places output on the named output
32 places `output' in the string
34 followed by the character `\e0'.
39 except that no more than
41 characters are written to
47 functions can be used to make functions like the first four by using the
49 method to process the argument.
51 Each of these functions converts, formats, and prints its arguments after
52 the first under control of the first argument.
53 The first argument is a character string which contains two types of objects:
54 plain characters, which are simply copied to the output stream,
55 and conversion specifications, each of which causes conversion and printing
56 of the next successive
59 Each conversion specification is introduced by the character
61 The remainder of the conversion specification includes
62 in the following order
65 Zero or more of following flags:
70 specifying that the value should be converted to an ``alternate form''.
77 conversions, this option has no effect. For
79 conversions, the precision of the number is increased to force the first
80 character of the output string to a zero. For
82 conversion, a non-zero result has the string
91 conversions, the result will always contain a decimal point, even if no
92 digits follow the point (normally, a decimal point only appears in the
93 results of those conversions if a digit follows the decimal point). For
97 conversions, trailing zeros are not removed from the result as they
101 a minus sign `\-' which specifies
103 of the converted value in the indicated field;
106 a `+' character specifying that there should always be
107 a sign placed before the number when using signed conversions.
110 a space specifying that a blank should be left before a positive number
111 during a signed conversion. A `+' overrides a space if both are used.
115 an optional digit string specifying a
117 if the converted value has fewer characters than the field width
118 it will be blank-padded on the left (or right,
119 if the left-adjustment indicator has been given) to make up the field width;
120 if the field width begins with a zero,
121 zero-padding will be done instead of blank-padding;
126 which serves to separate the field width from the next digit string;
129 an optional digit string specifying a
131 which specifies the number of digits to appear after the
132 decimal point, for e- and f-conversion, or the maximum number of characters
133 to be printed from a string;
138 specifying that a following
144 corresponds to a long integer
148 a character which indicates the type of
149 conversion to be applied.
151 A field width or precision may be `*' instead of a digit string.
152 In this case an integer
155 the field width or precision.
157 The conversion characters
158 and their meanings are
163 is converted to decimal, octal, or
164 hexadecimal notation respectively.
169 but use upper case instead of lower case.
174 is converted to decimal notation
175 in the style `[\fB\-\fR]ddd.ddd'
176 where the number of d's after the decimal point
177 is equal to the precision specification
182 if the precision is explicitly 0, no digits and
183 no decimal point are printed.
188 is converted in the style
189 `[\fB\-\fR]d\fB.\fRddd\fBe\fR\(+-dd'
190 where there is one digit before the decimal point and
191 the number after is equal to the
192 precision specification for the argument;
193 when the precision is missing,
194 6 digits are produced.
206 whichever gives full precision in minimum space.
215 is taken to be a string (character pointer)
216 and characters from the string are printed until
217 a null character or until
218 the number of characters indicated by the precision
219 specification is reached;
220 however if the precision is 0 or missing
221 all characters up to a null are printed.
226 is converted to decimal
230 Print a `%'; no argument is converted.
232 In no case does a non-existent or small field width
233 cause truncation of a field;
234 padding takes place only if the specified field
235 width exceeds the actual width.
236 Characters generated by
243 To print a date and time in the form `Sunday, July 3, 10:02',
248 are pointers to null-terminated strings:
251 printf("%s, %s %d, %02d:%02d", weekday, month, day, hour, min);
259 printf("pi = %.5f", 4*atan(1.0));