source: trunk/minix/man/man3/printf.3@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 6.1 KB
Line 
1.\" @(#)printf.3s 6.3 (Berkeley) 6/5/86
2.\"
3.TH PRINTF 3 "June 5, 1986"
4.AT 3
5.SH NAME
6printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf \- formatted output conversion
7.SH SYNOPSIS
8.nf
9.ft B
10#include <sys/types.h>
11#include <stdio.h>
12#include <stdarg.h>
13
14int printf(const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
15int fprintf(FILE *\fIstream\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
16int sprintf(char *\fIs\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
17int snprintf(char *\fIs\fP, size_t \fIn\fP, const char *\fIformat\fP \fR[\fP, \fIarg\fP\fR] ...\fP);
18int vprintf(const char *\fIformat\fP, va_list \fIargs\fP);
19int vfprintf(FILE *\fIstream\fP, const char *\fIformat\fP, va_list \fIargs\fP);
20int vsprintf(char *\fIs\fP, const char *\fIformat\fP, va_list \fIargs\fP);
21int vsnprintf(char *\fIs\fP, size_t \fIn\fP, const char *\fIformat\fP, va_list \fIargs\fP);
22.ft R
23.fi
24.SH DESCRIPTION
25.B Printf
26places output on the standard output stream
27.BR stdout .
28.B Fprintf
29places output on the named output
30.IR stream .
31.B Sprintf
32places `output' in the string
33.IR s ,
34followed by the character `\e0'.
35.B Snprintf
36(Minix-vmd only)
37is like
38.B sprintf
39except that no more than
40.IR n \-1
41characters are written to
42.I s
43followed by a `\e0'.
44.PP
45The
46.B v*printf
47functions can be used to make functions like the first four by using the
48.BR stdarg (3)
49method to process the argument.
50.PP
51Each of these functions converts, formats, and prints its arguments after
52the first under control of the first argument.
53The first argument is a character string which contains two types of objects:
54plain characters, which are simply copied to the output stream,
55and conversion specifications, each of which causes conversion and printing
56of the next successive
57.IR arg .
58.PP
59Each conversion specification is introduced by the character
60.BR % .
61The remainder of the conversion specification includes
62in the following order
63.TP
64\(bu
65Zero or more of following flags:
66.RS
67.TP
68\(bu
69a `#' character
70specifying that the value should be converted to an ``alternate form''.
71For
72.BR c ,
73.BR d ,
74.BR s ,
75and
76.BR u
77conversions, this option has no effect. For
78.B o
79conversions, the precision of the number is increased to force the first
80character of the output string to a zero. For
81.BR x ( X )
82conversion, a non-zero result has the string
83.BR 0x ( 0X )
84prepended to it. For
85.BR e ,
86.BR E ,
87.BR f ,
88.BR g ,
89and
90.BR G
91conversions, the result will always contain a decimal point, even if no
92digits follow the point (normally, a decimal point only appears in the
93results of those conversions if a digit follows the decimal point). For
94.B g
95and
96.B G
97conversions, trailing zeros are not removed from the result as they
98would otherwise be.
99.TP
100\(bu
101a minus sign `\-' which specifies
102.I "left adjustment"
103of the converted value in the indicated field;
104.TP
105\(bu
106a `+' character specifying that there should always be
107a sign placed before the number when using signed conversions.
108.TP
109\(bu
110a space specifying that a blank should be left before a positive number
111during a signed conversion. A `+' overrides a space if both are used.
112.RE
113.TP
114\(bu
115an optional digit string specifying a
116.I "field width;"
117if the converted value has fewer characters than the field width
118it will be blank-padded on the left (or right,
119if the left-adjustment indicator has been given) to make up the field width;
120if the field width begins with a zero,
121zero-padding will be done instead of blank-padding;
122.TP
123\(bu
124an optional period
125.RB ` . '
126which serves to separate the field width from the next digit string;
127.TP
128\(bu
129an optional digit string specifying a
130.I precision
131which specifies the number of digits to appear after the
132decimal point, for e- and f-conversion, or the maximum number of characters
133to be printed from a string;
134.TP
135\(bu
136the character
137.B l
138specifying that a following
139.BR d ,
140.BR o ,
141.BR x ,
142or
143.B u
144corresponds to a long integer
145.IR arg .
146.TP
147\(bu
148a character which indicates the type of
149conversion to be applied.
150.PP
151A field width or precision may be `*' instead of a digit string.
152In this case an integer
153.I arg
154supplies
155the field width or precision.
156.PP
157The conversion characters
158and their meanings are
159.TP
160.B dox
161The integer
162.I arg
163is converted to decimal, octal, or
164hexadecimal notation respectively.
165.TP
166.B X
167Like
168.BR x ,
169but use upper case instead of lower case.
170.TP
171.B f
172The float or double
173.I arg
174is converted to decimal notation
175in the style `[\fB\-\fR]ddd.ddd'
176where the number of d's after the decimal point
177is equal to the precision specification
178for the argument.
179If the precision
180is missing,
1816 digits are given;
182if the precision is explicitly 0, no digits and
183no decimal point are printed.
184.TP
185.B e
186The float or double
187.I arg
188is converted in the style
189`[\fB\-\fR]d\fB.\fRddd\fBe\fR\(+-dd'
190where there is one digit before the decimal point and
191the number after is equal to the
192precision specification for the argument;
193when the precision is missing,
1946 digits are produced.
195.TP
196.B g
197The float or double
198.I arg
199is printed in style
200.BR d ,
201in style
202.BR f ,
203or in
204style
205.BR e ,
206whichever gives full precision in minimum space.
207.TP
208.B c
209The character
210.I arg
211is printed.
212.TP
213.B s
214.I Arg
215is taken to be a string (character pointer)
216and characters from the string are printed until
217a null character or until
218the number of characters indicated by the precision
219specification is reached;
220however if the precision is 0 or missing
221all characters up to a null are printed.
222.TP
223.B u
224The unsigned integer
225.I arg
226is converted to decimal
227and printed.
228.TP
229.B %
230Print a `%'; no argument is converted.
231.PP
232In no case does a non-existent or small field width
233cause truncation of a field;
234padding takes place only if the specified field
235width exceeds the actual width.
236Characters generated by
237.B printf
238are printed by
239.BR putc (3).
240.PP
241.B Examples
242.br
243To print a date and time in the form `Sunday, July 3, 10:02',
244where
245.I weekday
246and
247.I month
248are pointers to null-terminated strings:
249.PP
250.RS
251printf("%s, %s %d, %02d:%02d", weekday, month, day, hour, min);
252.RE
253.PP
254To print
255.if n pi
256.if t \(*p
257to 5 decimals:
258.IP
259printf("pi = %.5f", 4*atan(1.0));
260.SH "SEE ALSO"
261.BR putc (3),
262.BR scanf (3),
263.BR ecvt (3),
264.BR stdarg (3).
Note: See TracBrowser for help on using the repository browser.