1 <!DOCTYPE HTML PUBLIC
"-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
7 <link rev=
"owner" href=
"mailto:scs@eskimo.com">
8 <link rev=
"made" href=
"mailto:scs@eskimo.com">
9 <title>section
7.2: Formatted Output -- Printf
</title>
10 <link href=
"sx10a.html" rev=precedes
>
11 <link href=
"sx10c.html" rel=precedes
>
12 <link href=
"sx10.html" rev=subdocument
>
15 <H2>section
7.2: Formatted Output -- Printf
</H2>
18 <p>To summarize the important points of this section:
19 <UL><li><TT>printf
</TT>'s output goes to the standard output,
20 just like
<TT>putchar
</TT>.
21 <li>Everything in
<TT>printf
</TT>'s format string
23 a plain character to be printed as-is,
24 or a
<TT>%
</TT>-specifier which
27 argument to be consumed, formatted, and printed.
29 a single
<TT>%
</TT>-specifier consumes
30 two or three arguments if the width or precision is
<TT>*
</TT>,
31 or zero arguments if the specifier is
<TT>%%
</TT>.)
32 <li>There's a fairly long list of conversion specifiers;
33 see the table on page
154.
34 <li>Always be careful that the conversions you request
35 (in the format string)
36 match the arguments you supply.
37 <li>You can ``print'' to a string
38 (instead of the standard output)
39 with
<TT>sprintf
</TT>.
40 (This is the usual way of converting numbers to strings in C;
41 the
<TT>itoa
</TT> function we were playing with
42 in section
3.6 on page
64
43 is nonstandard, and unnecessary.)
47 <a href=
"sx10a.html" rev=precedes
>prev
</a>
48 <a href=
"sx10c.html" rel=precedes
>next
</a>
49 <a href=
"sx10.html" rev=subdocument
>up
</a>
50 <a href=
"top.html">top
</a>
53 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
54 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
55 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>