OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / draft / man3 / printf.3
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
7 .\"
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
12 .\"
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 .\" GNU General Public License for more details.
17 .\"
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
21 .\" USA.
22 .\"
23 .\"
24 .\" Earlier versions of this page influenced the present text.
25 .\" It was derived from a Berkeley page with version
26 .\"       @(#)printf.3    6.14 (Berkeley) 7/30/91
27 .\" converted for Linux by faith@cs.unc.edu, updated by
28 .\" Helmut.Geyer@iwr.uni-heidelberg.de, agulbra@troll.no and Bruno Haible.
29 .\"
30 .\" 1999-11-25 aeb - Rewritten, using SUSv2 and C99.
31 .\" 2000-07-26 jsm28@hermes.cam.ac.uk - three small fixes
32 .\" 2000-10-16 jsm28@hermes.cam.ac.uk - more fixes
33 .\"
34 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi all rights reserved.
35 .\" Translated 1998-02-17, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
36 .\" Updated 2000-10-02, Kentaro Shirakata <argrath@ub32.org>
37 .\" Updated 2001-01-29, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2002-01-03, Kentaro Shirakata <argrath@ub32.org>
39 .\" Updated 2002-10-17, Kentaro Shirakata <argrath@ub32.org>
40 .\" Updated 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
42 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
43 .\" Updated 2009-03-03, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
44 .\"
45 .\" WORD: conversion specifier  ÊÑ´¹»ØÄê»Ò
46 .\" WORD: length modifier       Ä¹¤µ½¤¾þ»Ò
47 .\"
48 .TH PRINTF 3  2010-09-20 "GNU" "Linux Programmer's Manual"
49 .\"O .SH NAME
50 .SH Ì¾Á°
51 .\"O printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
52 .\"O vsnprintf \- formatted output conversion
53 printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
54 vsnprintf \- »ØÄꤵ¤ì¤¿½ñ¼°¤ËÊÑ´¹¤·¤Æ½ÐÎϤò¹Ô¤¦
55 .\"O .SH SYNOPSIS
56 .SH ½ñ¼°
57 .B #include <stdio.h>
58 .sp
59 .BI "int printf(const char *" format ", ...);"
60 .br
61 .BI "int fprintf(FILE *" stream ", const char *" format ", ...);"
62 .br
63 .BI "int sprintf(char *" str ", const char *" format ", ...);"
64 .br
65 .BI "int snprintf(char *" str ", size_t " size ", const char *" format ", ...);"
66 .sp
67 .B #include <stdarg.h>
68 .sp
69 .BI "int vprintf(const char *" format ", va_list " ap );
70 .br
71 .BI "int vfprintf(FILE *" stream ", const char *" format ", va_list " ap );
72 .br
73 .BI "int vsprintf(char *" str ", const char *" format ", va_list " ap );
74 .br
75 .BI "int vsnprintf(char *" str ", size_t " size ", const char *" format \
76 ", va_list " ap );
77 .sp
78 .in -4n
79 .\"O Feature Test Macro Requirements for glibc (see
80 .\"O .BR feature_test_macros (7)):
81 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
82 .RB ( feature_test_macros (7)
83 »²¾È):
84 .in
85 .sp
86 .ad l
87 .BR snprintf (),
88 .BR vsnprintf ():
89 .RS 4
90 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _ISOC99_SOURCE ||
91 _POSIX_C_SOURCE\ >=\ 200112L;
92 .br
93 or
94 .I "cc -std=c99"
95 .RE
96 .ad
97 .\"O .SH DESCRIPTION
98 .SH ÀâÌÀ
99 .\"O The functions in the
100 .\"O .BR printf ()
101 .\"O family produce output according to a
102 .\"O .I format
103 .\"O as described below.
104 .BR printf ()
105 ´Ø¿ô¥°¥ë¡¼¥×¤Ï¡¢°Ê²¼¤Ç½Ò¤Ù¤ë¤è¤¦¤Ë¡¢
106 .I format
107 ¤Ë½¾¤Ã¤Æ½ÐÎϤòÀ¸À®¤¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
108 .\"O The functions
109 .\"O .BR printf ()
110 .\"O and
111 .\"O .BR vprintf ()
112 .\"O write output to
113 .\"O .IR stdout ,
114 .\"O the standard output stream;
115 .\"O .BR fprintf ()
116 .\"O and
117 .\"O .BR vfprintf ()
118 .\"O write output to the given output
119 .\"O .IR stream ;
120 .\"O .BR sprintf (),
121 .\"O .BR snprintf (),
122 .\"O .BR vsprintf ()
123 .\"O and
124 .\"O .BR vsnprintf ()
125 .\"O write to the character string
126 .\"O .IR str .
127 .BR printf ()
128 ¤È
129 .BR vprintf ()
130 ¤Ï½ÐÎϤò
131 .I stdout
132 (ɸ½à½ÐÎÏ¥¹¥È¥ê¡¼¥à) ¤Ë½ñ¤­½Ð¤¹¡£
133 .BR fprintf ()
134 ¤È
135 .BR vfprintf ()
136 ¤Ï½ÐÎϤò»ØÄꤵ¤ì¤¿½ÐÎÏ
137 .I stream
138 ¤Ë½ñ¤­½Ð¤¹¡£
139 .BR sprintf (),
140 .BR snprintf (),
141 .BR vsprintf (),
142 .BR vsnprintf ()
143 ¤Ï½ÐÎϤòʸ»úÎó
144 .IR str
145 ¤Ë½ñ¤­¹þ¤à¡£
146 .PP
147 .\"O The functions
148 .\"O .BR snprintf ()
149 .\"O and
150 .\"O .BR vsnprintf ()
151 .\"O write at most
152 .\"O .I size
153 .\"O bytes (including the trailing null byte (\(aq\e0\(aq)) to
154 .\"O .IR str .
155 .BR snprintf ()
156 ¤È
157 .BR vsnprintf ()
158 ¤ÏºÇÂç¤Ç
159 .I size
160 ¥Ð¥¤¥È¤ò
161 .I str
162 ¤Ë½ñ¤­¹þ¤à
163 .RI ( size
164 ¤Ë¤Ïʸ»úÎó¤ò½ªÃ¼¤¹¤ë \(aq\e0\(aq ¤â¤ò´Þ¤Þ¤ì¤ë)¡£
165 .PP
166 .\"O The functions
167 .\"O .BR vprintf (),
168 .\"O .BR vfprintf (),
169 .\"O .BR vsprintf (),
170 .\"O .BR vsnprintf ()
171 .\"O are equivalent to the functions
172 .\"O .BR printf (),
173 .\"O .BR fprintf (),
174 .\"O .BR sprintf (),
175 .\"O .BR snprintf (),
176 .\"O respectively, except that they are called with a
177 .\"O .I va_list
178 .\"O instead of a variable number of arguments.
179 .\"O These functions do not call the
180 .\"O .I va_end
181 .\"O macro.
182 .\"O Because they invoke the
183 .\"O .I va_arg
184 .\"O macro, the value of
185 .\"O .I ap
186 .\"O is undefined after the call.
187 .\"O See
188 .\"O .BR stdarg (3).
189 .BR vprintf (),
190 .BR vfprintf (),
191 .BR vsprintf (),
192 .BR vsnprintf ()
193 ¤Î³Æ´Ø¿ô¤Ï¤½¤ì¤¾¤ì
194 .BR printf (),
195 .BR fprintf (),
196 .BR sprintf (),
197 .BR snprintf (),
198 ¤Î³Æ´Ø¿ô¤ÈÅù²Á¤Ç¤¢¤ê¡¢²ÄÊÑ¿ô°ú¤­¿ô¤ÎÂå¤ï¤ê¤Ë
199 .I va_list
200 ¤ò°ú¤­¿ô¤È¤·¤Æ¸Æ¤Ó½Ð¤µ¤ì¤ëÅÀ¤À¤±¤¬°Û¤Ê¤ë¡£
201 ¤³¤ì¤é¤Î´Ø¿ô¤Ç¤Ï
202 .I va_end
203 ¥Þ¥¯¥í¤Ï¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£
204 ¤³¤ì¤é¤Î´Ø¿ô¤Ï
205 .I va_arg
206 ¤ò¸Æ¤Ó½Ð¤¹¤Î¤Ç¡¢¸Æ¤Ó½Ð¤·¸å¤Î
207 .I ap
208 ¤ÎÃͤÏ̤ÄêµÁ¤Ç¤¢¤ë¡£
209 .BR stdarg (3)
210 ¤ò»²¾È¤Î¤³¤È¡£
211 .PP
212 .\"O These eight functions write the output under the control of a
213 .\"O .I format
214 .\"O string that specifies how subsequent arguments (or arguments accessed via
215 .\"O the variable-length argument facilities of
216 .\"O .BR stdarg (3))
217 .\"O are converted for output.
218 ¤³¤ì¤é¤Î 8 ¤Ä¤Î´Ø¿ô¤Ï
219 .I format
220 ʸ»úÎó¤ÎÀ©¸æ¤Ë½¾¤Ã¤Æ½ÐÎϤò½ñ¤­½Ð¤¹¡£
221 .I format
222 ʸ»úÎó¤Ï¡¢¤³¤ì¤Ë³¤¯°ú¤­¿ô (¤Þ¤¿¤Ï
223 .BR stdarg (3)
224 ¤Î²ÄÊÑĹ°ú¤­¿ôµ¡¹½¤ò»È¤Ã¤Æ¥¢¥¯¥»¥¹¤Ç¤­¤ë°ú¤­¿ô)
225 ¤ò¤É¤Î¤è¤¦¤ËÊÑ´¹¤·¤Æ½ÐÎϤ¹¤ë¤«¤ò»ØÄꤹ¤ë¡£
226
227 .\"O C99 and POSIX.1-2001 specify that the results are undefined if a call to
228 .\"O .BR sprintf (),
229 .\"O .BR snprintf (),
230 .\"O .BR vsprintf (),
231 .\"O or
232 .\"O .BR vsnprintf ()
233 .\"O would cause copying to take place between objects that overlap
234 .\"O (e.g., if the target string array and one of the supplied input arguments
235 .\"O refer to the same buffer).
236 .\"O See NOTES.
237 C99 ¤È POSIX.1-2001 ¤Ç¤Ï¡¢
238 .BR sprintf (),
239 .BR snprintf (),
240 .BR vsprintf (),
241 .BR vsnprintf ()
242 ¤Î¸Æ¤Ó½Ð¤·¤Ç¡¢ÈϰϤ¬½ÅÊ£¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È´Ö¤Ç¥³¥Ô¡¼¤¬È¯À¸¤¹¤ë¾ì¹ç¤Î
243 ·ë²Ì¤ÏÉÔÄê¤Ç¤¢¤ë¤Èµ¬Äꤵ¤ì¤Æ¤¤¤ë (Î㤨¤Ð¡¢½ÐÎÏÀè¤Îʸ»úÎó¤ÈÆþÎϤµ¤ì¤¿
244 °ú¤­¿ô¤Î°ì¤Ä¤¬Æ±¤¸¥Ð¥Ã¥Õ¥¡¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¤Ê¤É¤Ç¤¢¤ë)¡£
245 ¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¡£
246 .\"O .SS "Return value"
247 .SS ÊÖ¤êÃÍ
248 .\"O Upon successful return, these functions return the number of characters
249 .\"O printed (not including the
250 .\"O trailing \(aq\e0\(aq used to end output to strings).
251 À®¸ù»þ¤Ë¤Ï¡¢¾åµ­¤Î´Ø¿ô¤Ï½ñ¤­¹þ¤Þ¤ì¤¿Ê¸»ú¿ô¤òÊÖ¤¹
252 (ʸ»úÎó¤ÎºÇ¸å¤ò¼¨¤¹¤¿¤á¤Ë»ÈÍѤ¹¤ë \(aq\e0\(aq ¤Ï¿ô¤Ë´Þ¤Þ¤ì¤Ê¤¤)¡£
253
254 .\"O The functions
255 .\"O .BR snprintf ()
256 .\"O and
257 .\"O .BR vsnprintf ()
258 .\"O do not write more than
259 .\"O .I size
260 .\"O bytes (including the trailing \(aq\e0\(aq).
261 .\"O If the output was truncated due to this limit then the return value
262 .\"O is the number of characters (not including the trailing \(aq\e0\(aq)
263 .\"O which would have been written to the final string if enough space
264 .\"O had been available.
265 .\"O Thus, a return value of
266 .\"O .I size
267 .\"O or more means that the output was truncated.
268 .\"O (See also below under NOTES.)
269 .BR snprintf ()
270 ¤È
271 .BR vsnprintf ()
272 ¤Ï¡¢
273 .I size
274 ¥Ð¥¤¥È¤ò±Û¤¨¤ëʸ»ú¿ô¤ò½ñ¤­¹þ¤Þ¤Ê¤¤
275 .RI ( size
276 ¤Ë¤Ïʸ»úÎó¤ò½ªÃ¼¤¹¤ë \(aq\e0\(aq ¤â¤ò´Þ¤Þ¤ì¤ë)¡£
277 ¤³¤ÎÀ©¸Â¤Ë¤è¤Ã¤Æ½ÐÎϤ¬ÀÚ¤êµÍ¤á¤é¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
278 ¤â¤·½½Ê¬¤Ê¥¹¥Ú¡¼¥¹¤¬¤¢¤ì¤Ð½ñ¤­¹þ¤Þ¤ì¤¿¤Ç¤¢¤í¤¦Ê¸»ú¤Î¸Ä¿ô
279 (ʸ»úÎó¤ò½ªÃ¼¤¹¤ë \(aq\e0\(aq ¤ò½ü¤¯) ¤òÊÖ¤¹¡£
280 ½¾¤Ã¤Æ¡¢ÊÖ¤êÃͤ¬
281 .I size
282 °Ê¾å¤À¤Ã¤¿¾ì¹ç¡¢½ÐÎϤ¬ÀÚ¤êµÍ¤á¤é¤ì¤¿¤³¤È¤ò°ÕÌ£¤¹¤ë
283 (¸å½Ò¤ÎÃí°Õ¤â»²¾È¤Î¤³¤È)¡£
284
285 .\"O If an output error is encountered, a negative value is returned.
286 ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï¡¢Éé¤Î¿ô¤òÊÖ¤¹¡£
287 .\"O .SS "Format of the format string"
288 .SS ¥Õ¥©¡¼¥Þ¥Ã¥Èʸ»úÎó¤Î¥Õ¥©¡¼¥Þ¥Ã¥È
289 .\"O The format string is a character string, beginning and ending
290 .\"O in its initial shift state, if any.
291 ¥Õ¥©¡¼¥Þ¥Ã¥Èʸ»úÎó¤Ïʸ»ú¤ÎÎó¤Ç¡¢
292 (¤â¤·¤¢¤ë¤Ê¤é) ½é´ü¥·¥Õ¥È¾õÂ֤ǻϤޤꡢ½é´ü¥·¥Õ¥È¾õÂ֤ǽª¤ï¤ë¡£
293 .\"O The format string is composed of zero or more directives: ordinary
294 .\"O characters (not
295 .\"O .BR % ),
296 .\"O which are copied unchanged to the output stream;
297 .\"O and conversion specifications, each of which results in fetching zero or
298 .\"O more subsequent arguments.
299 ¥Õ¥©¡¼¥Þ¥Ã¥ÈÍѤÎʸ»úÎó¤Ï 0 ¸Ä°Ê¾å¤ÎÌ¿Îá (directives) ¤Ë¤è¤Ã¤Æ¹½À®¤µ¤ì¤ë¡£
300 Ì¿Îá¤Ë¤Ï¡¢Ä̾ïʸ»ú¤ÈÊÑ´¹»ØÄê (conversion specifications) ¤¬¤¢¤ë¡£
301 Ä̾ïʸ»ú¤Ï
302 .B %
303 °Ê³°¤Îʸ»ú¤Ç¡¢½ÐÎÏ¥¹¥È¥ê¡¼¥à¤Ë¤½¤Î¤Þ¤Þ¥³¥Ô¡¼¤µ¤ì¤ë¡£
304 ÊÑ´¹»ØÄê¤Ï¡¢¤½¤ì¤¾¤ì¤¬ 0 ¸Ä°Ê¾å¤Î°ú¤­¿ô¤ò¼è¤ë¡£
305 .\"O Each conversion specification is introduced by
306 .\"O the character
307 .\"O .BR % ,
308 .\"O and ends with a
309 .\"O .IR "conversion specifier" .
310 ³ÆÊÑ´¹»ØÄê¤Ïʸ»ú
311 .B %
312 ¤Ç»Ï¤Þ¤ê¡¢
313 .I "ÊÑ´¹»ØÄê»Ò (conversion specifier)"
314 ¤Ç½ª¤ï¤ë¡£
315 .\"O In between there may be (in this order) zero or more
316 .\"O .IR flags ,
317 .\"O an optional minimum
318 .\"O .IR "field width" ,
319 .\"O an optional
320 .\"O .I precision
321 .\"O and an optional
322 .\"O .IR "length modifier" .
323 .B %
324 ¤ÈÊÑ´¹»ØÄê»Ò¤Î´Ö¤Ë¤Ï¡¢0 ¸Ä°Ê¾å¤Î
325 .I ¥Õ¥é¥° ¡¢
326 ºÇ¾®
327 .I ¥Õ¥£¡¼¥ë¥ÉÉý ¡¢
328 .I ÀºÅÙ ¡¢
329 .I Ä¹¤µ½¤¾þ»Ò
330 ¤ò (¤³¤Î½ç½ø¤Ç) ÃÖ¤¯¤³¤È¤¬¤Ç¤­¤ë¡£
331
332 .\"O The arguments must correspond properly (after type promotion) with the
333 .\"O conversion specifier.
334 .\"O By default, the arguments are used in the order
335 .\"O given, where each \(aq*\(aq and each conversion specifier asks for the next
336 .\"O argument (and it is an error if insufficiently many arguments are given).
337 °ú¤­¿ô¤Ï (·¿¤Î³Ê¾å¤²¤Î¸å¤Ï) ÊÑ´¹»ØÄê»Ò¤¬É½¤¹·¿¤ÈÀµ³Î¤ËÂбþ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
338 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢\(aq*\(aq ¤äÊÑ´¹»ØÄê»Ò¤¬½Ð¤Æ¤¯¤ëËè¤Ë¼¡¤Î°ú¤­¿ô¤òÍ׵ᤵ¤ì¡¢
339 °ú¤­¿ô¤Ï»ØÄꤵ¤ì¤¿½ç½ø¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤¯
340 (»ØÄꤵ¤ì¤¿°ú¤­¿ô¤Î¸Ä¿ô¤¬ÉÔ½½Ê¬¤Ê¤é¥¨¥é¡¼¤È¤Ê¤ë)¡£
341 .\"O One can also specify explicitly which argument is taken,
342 .\"O at each place where an argument is required, by writing "%m$" instead
343 .\"O of \(aq%\(aq and "*m$" instead of \(aq*\(aq,
344 .\"O where the decimal integer m denotes
345 .\"O the position in the argument list of the desired argument, indexed starting
346 .\"O from 1.
347 .\"O Thus,
348 .\"O .in +4n
349 .\"O .nf
350 .\"O
351 .\"O printf("%*d", width, num);
352 .\"O
353 .\"O .fi
354 .\"O .in
355 .\"O and
356 .\"O .in +4n
357 .\"O .nf
358 .\"O
359 .\"O printf("%2$*1$d", width, num);
360 .\"O
361 .\"O .fi
362 .\"O .in
363 ¤Þ¤¿¡¢°ú¤­¿ô¤¬É¬Íפʲսê¤Ç \(aq%\(aq ¤ÎÂå¤ï¤ê¤Ë "%m$"¡¢
364 \(aq*\(aq¤ÎÂå¤ï¤ê¤Ë "*m$" ¤È½ñ¤¯¤³¤È¤Ç¡¢
365 ÌÀ¼¨Åª¤Ë¤É¤Î°ú¤­¿ô¤ò»ÈÍѤ¹¤ë¤«¤ò»ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤ë¡£
366 ¤³¤³¤Ç 10¿Ê¤ÎÀ°¿ô m ¤Ï´õ˾¤Î°ú¤­¿ô¤Î°ú¤­¿ô¥ê¥¹¥È¤Ç¤Î°ÌÃÖ¤ò¼¨¤¹
367 (ºÇ½é¤Î°ú¤­¿ô¤ÎÈֹ椬 1 ¤Ç¤¢¤ë)¡£
368 ½¾¤Ã¤Æ¡¢°Ê²¼¤ÎÆó¤Ä¤ÏÅù²Á¤Ç¤¢¤ë¡£
369 .in +4n
370 .nf
371
372 printf("%*d", width, num);
373
374 printf("%2$*1$d", width, num);
375
376 .fi
377 .in
378 ¤ÏÅù²Á¤Ç¤¢¤ë¡£
379 .\"O are equivalent.
380 .\"O The second style allows repeated references to the
381 .\"O same argument.
382 .\"O The C99 standard does not include the style using \(aq$\(aq,
383 .\"O which comes from the Single UNIX Specification.
384 .\"O If the style using
385 .\"O \(aq$\(aq is used, it must be used throughout for all conversions taking an
386 .\"O argument and all width and precision arguments, but it may be mixed
387 .\"O with "%%" formats which do not consume an argument.
388 .\"O There may be no
389 .\"O gaps in the numbers of arguments specified using \(aq$\(aq; for example, if
390 .\"O arguments 1 and 3 are specified, argument 2 must also be specified
391 .\"O somewhere in the format string.
392 ÆóÈÖÌܤνñ¤­Êý¤Ç¤ÏƱ¤¸°ú¤­¿ô¤ò·«¤êÊÖ¤·»²¾È¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
393 C99 É¸½à¤Ë¤Ï¡¢ Single UNIX Specification Í³Íè¤Î \(aq$\(aq ¤ò»È¤Ã¤¿½ñ¤­Êý¤Ï´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¡£
394 \(aq$\(aq ¤ò»È¤Ã¤¿¥¹¥¿¥¤¥ë¤ò»È¤¦¤È¡¢°ú¤­¿ô¤ò¼è¤ëÊÑ´¹µÚ¤ÓÉý¤ÈÀºÅ٤ΰú¤­¿ô¤ò
395 Á´¤Æ¤³¤Î¥¹¥¿¥¤¥ë¤Ç»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤¬¡¢
396 °ú¤­¿ô¤ò¾ÃÈñ¤·¤Ê¤¤ "%%" ¥Õ¥©¡¼¥Þ¥Ã¥È¤Èº®¤¶¤Ã¤Æ¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
397 \(aq$\(aq ¤Ç»ØÄꤵ¤ì¤ë°ú¤­¿ô¤ÎÈÖ¹æ¤Ë¶õ¤­¤¬¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
398 Î㤨¤Ð¡¢¤â¤·°ú¤­¿ô 1 ¤È 3 ¤¬»ØÄꤵ¤ì¤ë¤È¡¢°ú¤­¿ô 2 ¤â¥Õ¥©¡¼¥Þ¥Ã¥Èʸ»úÎó¤Î¤É¤³¤«¤Ç
399 »ØÄꤵ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
400
401 .\"O For some numeric conversion a radix character ("decimal point") or
402 .\"O thousands' grouping character is used.
403 .\"O The actual character used
404 .\"O depends on the
405 .\"O .B LC_NUMERIC
406 .\"O part of the locale.
407 .\"O The POSIX locale
408 .\"O uses \(aq.\(aq as radix character, and does not have a grouping character.
409 ¿ôÃÍÊÑ´¹¤Ë¤Ï¾®¿ôÅÀ¤ä 1000 Ã±°Ì¤Î¶èÀÚ¤êʸ»ú¤ò»È¤¦¤â¤Î¤â¤¢¤ë¡£
410 ¼ÂºÝ¤Ë¤É¤Îʸ»ú¤ò»È¤¦¤«¤Ï¥í¥±¡¼¥ë¤Î
411 .B LC_NUMERIC
412 ¤Ë¤è¤ë¡£
413 POSIX ¥í¥±¡¼¥ë¤Ç¤Ï¾®¿ôÅÀ¤Ë \(aq.\(aq ¤òÍѤ¤¡¢
414 ¶èÀÚ¤êʸ»ú¤Ï»È¤ï¤Ê¤¤¡£
415 .\"O Thus,
416 ½¾¤Ã¤Æ¡¢
417 .in +4n
418 .nf
419
420 printf("%\(aq.2f", 1234567.89);
421
422 .fi
423 .in
424 .\"O results in "1234567.89" in the POSIX locale, in "1234567,89" in the
425 .\"O nl_NL locale, and in "1.234.567,89" in the da_DK locale.
426 ¤Ï¡¢ POSIX ¥í¥±¡¼¥ë¤Ç¤Ï "1234567.89" ¡¢ nl_NL ¥í¥±¡¼¥ë¤Ç¤Ï "1234567,89"¡¢
427 da_DK ¥í¥±¡¼¥ë¤Ç¤Ï "1.234.567,89" ¤È¤Ê¤ë¡£
428 .\"O .SS "The flag characters"
429 .SS ¥Õ¥é¥°Ê¸»ú
430 .\"O The character % is followed by zero or more of the following flags:
431 % Ê¸»ú¤Î¸å¤í¤Ë¤Ï 0 ¸Ä°Ê¾å¤Î¥Õ¥é¥°Ê¸»ú¤¬Â³¤¯¡£
432 .TP
433 .\"O .B #
434 .\"O The value should be converted to an "alternate form".
435 .B #
436 ÃͤϡÖÊ̤ηÁ¼°¡×¤ËÊÑ´¹¤µ¤ì¤ë¡£
437 .\"O For
438 .\"O .B o
439 .\"O conversions, the first character of the output string is made zero
440 .\"O (by prefixing a 0 if it was not zero already).
441 .B o
442 ÊÑ´¹¤Î¾ì¹ç¡¢(ÀèƬʸ»ú¤¬ 0 ¤Ë¤Ê¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç¤ËÀèƬ¤Ë 0 ¤òÄɲ乤뤳¤È¤Ç)
443 ½ÐÎÏʸ»úÎó¤ÎºÇ½é¤Îʸ»ú¤ò 0 ¤Ë¤¹¤ë¡£
444 .\"O For
445 .\"O .B x
446 .\"O and
447 .\"O .B X
448 .\"O conversions, a nonzero result has the string "0x" (or "0X" for
449 .\"O .B X
450 .\"O conversions) prepended to it.
451 .B x
452 ¤È
453 .B X
454 ÊÑ´¹¤Î¾ì¹ç¡¢¿ôÃͤ¬ 0 ¤Ç¤Ê¤¤¤È¤­¤Ë¤Ïʸ»úÎó "0x"
455 .RB ( X
456 ÊÑ´¹¤Î¾ì¹ç¤Ë¤Ï "0X") ¤¬Á°¤ËÉÕÍ¿¤µ¤ì¤ë¡£
457 .\"O For
458 .\"O .BR a ,
459 .\"O .BR A ,
460 .\"O .BR e ,
461 .\"O .BR E ,
462 .\"O .BR f ,
463 .\"O .BR F ,
464 .\"O .BR g ,
465 .\"O and
466 .\"O .B G
467 .\"O conversions, the result will always contain a decimal point, even if no
468 .\"O digits follow it (normally, a decimal point appears in the results of those
469 .\"O conversions only if a digit follows).
470 .\"O For
471 .BR a ,
472 .BR A ,
473 .BR e ,
474 .BR E ,
475 .BR f ,
476 .BR F ,
477 .BR g ,
478 .B G
479 ÊÑ´¹¤Ç¤Ï¡¢ ¾®¿ôÅÀ¤Ë³¤¯¿ô»ú¤¬¤Ê¤¯¤Æ¤â¡¢
480 ½ÐÎϤˤϾï¤Ë¾®¿ôÅÀ¤¬´Þ¤Þ¤ì¤ë
481 (Ä̾ï¤Ï¡¢¾®¿ôÅÀ¤Î¸å¤Ë¿ô»ú¤¬Â³¤¯¾ì¹ç¤Ë¤Î¤ß¡¢
482 ¾®¿ôÅÀ¤¬É½¼¨¤µ¤ì¤ë)¡£
483 .\"O .B g
484 .\"O and
485 .\"O .B G
486 .\"O conversions, trailing zeros are not removed from the result as they would
487 .\"O otherwise be.
488 .B g
489 ¤È
490 .B G
491 ÊÑ´¹¤Î¾ì¹ç¡¢Â¾¤ÎÊÑ´¹¤È¤Ï°Û¤Ê¤ê¡¢ËöÈø¤Î¥¼¥í¤¬ÊÑ´¹·ë²Ì¤«¤éºï½ü¤µ¤ì¤Ê¤¤¡£
492 .\"O For other conversions, the result is undefined.
493 ¤½¤Î¾¤ÎÊÑ´¹¤Ç¤Ï¡¢·ë²Ì¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£
494 .TP
495 .B \&0
496 .\"O The value should be zero padded.
497 .\"O For
498 .\"O .BR d ,
499 .\"O .BR i ,
500 .\"O .BR o ,
501 .\"O .BR u ,
502 .\"O .BR x ,
503 .\"O .BR X ,
504 .\"O .BR a ,
505 .\"O .BR A ,
506 .\"O .BR e ,
507 .\"O .BR E ,
508 .\"O .BR f ,
509 .\"O .BR F ,
510 .\"O .BR g ,
511 .\"O and
512 .\"O .B G
513 .\"O conversions, the converted value is padded on the left with zeros rather
514 .\"O than blanks.
515 Ãͤò¥¼¥í¤ÇËä¤á¤ë¡£
516 .BR d ,
517 .BR i ,
518 .BR o ,
519 .BR u ,
520 .BR x ,
521 .BR X ,
522 .BR a ,
523 .BR A ,
524 .BR e ,
525 .BR E ,
526 .BR f ,
527 .BR F ,
528 .BR g ,
529 .B G
530 ÊÑ´¹¤Ç¤Ï¡¢ÊÑ´¹¤·¤¿Ãͤκ¸Â¦¤ò¶õÇòʸ»ú¤ÎÂå¤ï¤ê¤Ë¥¼¥í¤ÇËä¤á¤ë¡£
531 .\"O If the
532 .\"O .B \&0
533 .\"O and
534 .\"O .B \-
535 .\"O flags both appear, the
536 .\"O .B \&0
537 .\"O flag is ignored.
538 .B \&0
539 ¤È
540 .B \-
541 ¤¬Î¾Êý¤È¤â»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢
542 .B \&0
543 ¥Õ¥é¥°¤Ï̵»ë¤µ¤ì¤ë¡£
544 .\"O If a precision is given with a numeric conversion
545 .\"O .RB ( d ,
546 .\"O .BR i ,
547 .\"O .BR o ,
548 .\"O .BR u ,
549 .\"O .BR x ,
550 .\"O and
551 .\"O .BR X ),
552 .\"O the
553 .\"O .B \&0
554 .\"O flag is ignored.
555 ÀºÅÙ¤¬¿ôÃÍÊÑ´¹
556 .RB ( d ,
557 .BR i ,
558 .BR o ,
559 .BR u ,
560 .BR x ,
561 .BR X )
562 ¤ÈƱ»þ¤Ë»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
563 .B \&0
564 ¥Õ¥é¥°¤Ï̵»ë¤µ¤ì¤ë¡£
565 .\"O For other conversions, the behavior is undefined.
566 ¤½¤Î¾¤ÎÊÑ´¹¤Ç¤Ï¡¢Æ°ºî¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£
567 .TP
568 .B \-
569 .\"O The converted value is to be left adjusted on the field boundary.
570 .\"O (The default is right justification.)
571 .\"O Except for
572 .\"O .B n
573 .\"O conversions, the converted value is padded on the right with blanks, rather
574 .\"O than on the left with blanks or zeros.
575 .\"O A
576 ÊÑ´¹Ãͤò¥Õ¥£¡¼¥ë¥É¶­³¦¤Çº¸Â·¤¨¤Ë¤¹¤ë
577 (¥Ç¥Õ¥©¥ë¥È¤Ï±¦Â·¤¨¤Ç¤¢¤ë)¡£
578 .B n
579 ÊÑ´¹°Ê³°¤Ç¤Ï¡¢ÊÑ´¹¤µ¤ì¤¿ÃͤÏ
580 º¸Â¦¤Ç¤Ï¤Ê¤¯±¦Â¦¤ò¶õÇòʸ»ú¤ä¥¼¥í¤ÇËä¤á¤é¤ì¤ë¡£
581 .\"O .B \-
582 .\"O overrides a
583 .\"O .B \&0
584 .\"O if both are given.
585 .B \-
586 ¤È
587 .B \&0
588 ¤ÎξÊý¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
589 .B \-
590 ¤¬Í¥À褵¤ì¤ë¡£
591 .TP
592 .\"O .B \(aq \(aq
593 .B ' '
594 .\"O (a space) A blank should be left before a positive number
595 .\"O (or empty string) produced by a signed conversion.
596 (1¸Ä¤ÎȾ³Ñ¥¹¥Ú¡¼¥¹)
597 Éä¹æÉÕ¤­ÊÑ´¹¤ÇÀ¸À®¤µ¤ì¤¿Àµ¤Î¿ô»ú¤ÎÁ°¤Ë¶õÇò (¤Þ¤¿¤Ï¶õʸ»úÎó) ¤¬ÃÖ¤«¤ì¤ë¡£
598 .TP
599 .\"O .B +
600 .\"O A sign (+ or \-) should always be placed before a number produced by a signed
601 .\"O conversion.
602 .\"O By default a sign is used only for negative numbers.
603 .\"O A
604 .\"O .B +
605 .\"O overrides a space if both are used.
606 .B +
607 Éä¹æÉÕ¤­ÊÑ´¹¤Ë¤è¤Ã¤Æ½ÐÎϤµ¤ì¤ë¿ô»ú¤ÎÁ°¤Ë¡¢¾ï¤ËÉä¹æ (+ ¤« \-) ¤¬ÃÖ¤«¤ì¤ë¡£
608 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Éä¹æ¤ÏÉé¤Î¿ô»ú¤Î¾ì¹ç¤Î¤ßÉÕÍ¿¤µ¤ì¤ë¡£
609 .B +
610 ¤ÈȾ³Ñ¥¹¥Ú¡¼¥¹¤Î
611 ξÊý¤¬»È¤ï¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
612 .B +
613 ¤¬Í¥À褵¤ì¤ë¡£
614 .PP
615 .\"O The five flag characters above are defined in the C standard.
616 .\"O The SUSv2 specifies one further flag character.
617 ¾åµ­¤Î 5 ¤Ä¤Î¥Õ¥é¥°¤Ï C É¸½à¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
618 SUSv2 ¤Ç¤Ï¡¢¤µ¤é¤Ë¤â¤¦°ì¤Ä¥Õ¥é¥°Ê¸»ú¤¬µ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
619 .TP
620 .B \(aq
621 .\"O For decimal conversion
622 .\"O .RB ( i ,
623 .\"O .BR d ,
624 .\"O .BR u ,
625 .\"O .BR f ,
626 .\"O .BR F ,
627 .\"O .BR g ,
628 .\"O .BR G )
629 .\"O the output is to be grouped with thousands' grouping characters
630 .\"O if the locale information indicates any.
631 .\"O Note that many versions of
632 .\"O .BR gcc (1)
633 .\"O cannot parse this option and will issue a warning.
634 .\"O SUSv2 does not
635 .\"O include %\(aqF.
636 10¿Ê¿ôÊÑ´¹
637 .RB ( i ,
638 .BR d ,
639 .BR u ,
640 .BR f ,
641 .BR F ,
642 .BR g ,
643 .BR G )
644 ¤Ë¤ª¤¤¤Æ¡¢¥í¥±¡¼¥ë¾ðÊó¤Ë»ØÄ꤬¤¢¤ì¤Ð 1000 Ã±°Ì¤Î¶èÀÚ¤êʸ»ú¤ò½ÐÎϤ¹¤ë¡£
645 .BR gcc (1)
646 ¤Î¿¤¯¤Î¥Ð¡¼¥¸¥ç¥ó¤Ï¡¢¤³¤Î¥ª¥×¥·¥ç¥ó¤ò²ò¼á¤¹¤ë¤³¤È¤¬¤Ç¤­¤º¡¢
647 ·Ù¹ð¤ò½ÐÎϤ¹¤ë¤³¤È¤ËÃí°Õ¤»¤è¡£
648 %\(aqF ¤Ï SUSv2 ¤Ë¤Ï´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¡£
649 .PP
650 .\"O glibc 2.2 adds one further flag character.
651 glibc 2.2 ¤Ç¤Ï¡¢¤µ¤é¤Ë°ì¤Ä¥Õ¥é¥°Ê¸»ú¤¬Äɲ䵤ì¤Æ¤¤¤ë¡£
652 .TP
653 .B I
654 .\"O For decimal integer conversion
655 .\"O .RB ( i ,
656 .\"O .BR d ,
657 .\"O .BR u )
658 .\"O the output uses the locale's alternative output digits, if any.
659 .\"O For example, since glibc 2.2.3 this will give Arabic-Indic digits
660 .\"O in the Persian ("fa_IR") locale.
661 .\"O .\" outdigits keyword in locale file
662 10¿ÊÀ°¿ôÊÑ´¹
663 .RB ( i ,
664 .BR d ,
665 .BR u )
666 ¤Ë¤ª¤¤¤Æ¡¢¥í¥±¡¼¥ë¤ÎÂåÂؽÐÎÏ¿ô»ú¤¬¤¢¤ì¤Ð¡¢¤½¤ì¤òÍѤ¤¤Æ½ÐÎϤ¹¤ë¡£
667 Î㤨¤Ð¡¢ glibc 2.2.3 °Ê¹ß¤Ç¤Ï¡¢¥Ú¥ë¥·¥¢ ("fa_IR") ¥í¥±¡¼¥ë¤Ç
668 ¥¢¥é¥Ó¥¢¿ô»ú (Arabic-Indic digits) ¤ò½ÐÎϤǤ­¤ë¡£
669 .\" ¥í¥±¡¼¥ë¥Õ¥¡¥¤¥ë¤Ë¤Ï outdigits ¤È¤¤¤¦¥­¡¼¥ï¡¼¥É¤¬¤¢¤ë¡£
670 .\"O .SS "The field width"
671 .SS ¥Õ¥£¡¼¥ë¥ÉÉý
672 .\"O An optional decimal digit string (with nonzero first digit) specifying
673 .\"O a minimum field width.
674 .\"O If the converted value has fewer characters
675 .\"O than the field width, it will be padded with spaces on the left
676 .\"O (or right, if the left-adjustment flag has been given).
677 ºÇ¾®¤Î¥Õ¥£¡¼¥ë¥ÉÉý¤ò»ØÄꤹ¤ë 10¿Ê¿ô¤Î¿ôÃÍʸ»úÎó (ʸ»úÎó¤ÎºÇ½é¤Îʸ»ú¤Ï
678 ¥¼¥í°Ê³°)¡£ËܹàÌܤϥª¥×¥·¥ç¥ó¤Ç¤¢¤ë¡£
679 ÊÑ´¹¤µ¤ì¤¿ÃͤÎʸ»ú¿ô¤¬¥Õ¥£¡¼¥ë¥ÉŤè¤ê¤â¾¯¤Ê¤¤¾ì¹ç¡¢
680 ¥Õ¥£¡¼¥ë¥É¤Îº¸Â¦¤ò¥¹¥Ú¡¼¥¹¤ÇËä¤á¤ë
681 (º¸Â·¤¨¤Î¥Õ¥é¥°¤¬¤¢¤ë¾ì¹ç¤Ï±¦Â¦¤òËä¤á¤ë)¡£
682 .\"O Instead of a decimal digit string one may write "*" or "*m$"
683 .\"O (for some decimal integer \fIm\fP) to specify that the field width
684 .\"O is given in the next argument, or in the \fIm\fP-th argument, respectively,
685 .\"O which must be of type
686 .\"O .IR int .
687 10¿Ê¿ô¤Îʸ»úÎó¤ÎÂå¤ï¤ê¤Ë "*" ¤ä "*m$" (\fIm\fP ¤Ï 10¿ÊÀ°¿ô) ¤ò½ñ¤¯¤³¤È¤â¤Ç¤­¤ë¡£
688 "*" ¤È "*m$" ¤Ï¤½¤ì¤¾¤ì¡¢¼¡¤Î°ú¤­¿ô¤È \fIm\fP ÈÖÌܤΰú¤­¿ô¤ò¥Õ¥£¡¼¥ë¥ÉÉý¤È¤·¤Æ
689 »È¤¦¤³¤È¤ò»ØÄꤹ¤ë (¤³¤ì¤é¤Î°ú¤­¿ô¤Ï
690 .I int
691 ·¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤)¡£
692 .\"O A negative field width is taken as a \(aq\-\(aq flag followed by a
693 .\"O positive field width.
694 ¥Õ¥£¡¼¥ë¥ÉÉý¤ËÉé¤Î¿ô¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢
695 \(aq\-\(aq ¥Õ¥é¥°¤ÈÀµ¤Î¿ô¤Î¥Õ¥£¡¼¥ë¥ÉÉý¤È¤·¤Æ°·¤ï¤ì¤ë¡£
696 .\"O In no case does a nonexistent or small field width cause truncation of a
697 .\"O field; if the result of a conversion is wider than the field width, the
698 .\"O field is expanded to contain the conversion result.
699 ¥Õ¥£¡¼¥ë¥ÉÉý¤¬¾®¤µ¤«¤Ã¤¿¤ê»ØÄ꤬¤Ê¤«¤Ã¤¿¤ê¤·¤Æ¤â¡¢¥Õ¥£¡¼¥ë¥É¤¬ÀÚ¤êµÍ¤á¤é¤ì¤ë
700 ¤³¤È¤Ï¤Ê¤¤¡£¤â¤·ÊÑ´¹·ë²Ì¤¬¥Õ¥£¡¼¥ë¥ÉÉý¤è¤ê¤â¹­¤«¤Ã¤¿¾ì¹ç¡¢
701 ¥Õ¥£¡¼¥ë¥É¤ÏÊÑ´¹·ë²Ì¤¬Æþ¤ëÉý¤Ë¹­¤²¤é¤ì¤ë¡£
702 .\"O .SS "The precision"
703 .SS ÀºÅÙ
704 .\"O An optional precision, in the form of a period (\(aq.\(aq)  followed by an
705 .\"O optional decimal digit string.
706 ¥ª¥×¥·¥ç¥ó¤Ç¤¢¤ëÀºÅ٤ϡ¢¥Ô¥ê¥ª¥É (\(aq.\(aq) ¤È¤½¤ì¤Ë³¤¯10¿Ê¿ô¤È¤¤¤¦
707 ·Á¼°¤Ç»ØÄꤹ¤ë (10¿Ê¿ô¤Ï¥ª¥×¥·¥ç¥ó) ¡£
708 .\"O Instead of a decimal digit string one may write "*" or "*m$"
709 .\"O (for some decimal integer m) to specify that the precision
710 .\"O is given in the next argument, or in the m-th argument, respectively,
711 .\"O which must be of type
712 .\"O .IR int .
713 10¿Ê¿ô¤Îʸ»úÎó¤ÎÂå¤ï¤ê¤Ë "*" ¤ä "*m$" (m ¤Ï 10 ¿ÊÀ°¿ô)¤ò½ñ¤¯¤³¤È¤â¤Ç¤­¤ë¡£
714 "*" ¤È "*m$" ¤Ï¤½¤ì¤¾¤ì¡¢¼¡¤Î°ú¤­¿ô¤È m ÈÖÌܤΰú¤­¿ô¤òÀºÅ٤Ȥ·¤Æ
715 »È¤¦¤³¤È¤ò»ØÄꤹ¤ë (¤³¤ì¤é¤Î°ú¤­¿ô¤Ï
716 .I int
717 ·¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤)¡£
718 .\"O If the precision is given as just \(aq.\(aq, or the precision is negative,
719 .\"O the precision is taken to be zero.
720 ÀºÅ٤Ȥ·¤Æ \(aq.\(aq ¤À¤±¤¬»ØÄꤵ¤ì¤¿¤ê¡¢ÀºÅÙ¤¬Éé¤Î¿ô¤À¤Ã¤¿¾ì¹ç¡¢
721 ÀºÅ٤ϥ¼¥í¤È¤ß¤Ê¤µ¤ì¤ë¡£
722 .\"O This gives the minimum number of digits to appear for
723 .\"O .BR d ,
724 .\"O .BR i ,
725 .\"O .BR o ,
726 .\"O .BR u ,
727 .\"O .BR x ,
728 .\"O and
729 .\"O .B X
730 .\"O conversions, the number of digits to appear after the radix character for
731 .\"O .BR a ,
732 .\"O .BR A ,
733 .\"O .BR e ,
734 .\"O .BR E ,
735 .\"O .BR f ,
736 .\"O and
737 .\"O .B F
738 .\"O conversions, the maximum number of significant digits for
739 .\"O .B g
740 .\"O and
741 .\"O .B G
742 .\"O conversions, or the maximum number of characters to be printed from a
743 .\"O string for
744 .\"O .B s
745 .\"O and
746 .\"O .B S
747 .\"O conversions.
748 .BR d ,
749 .BR i ,
750 .BR o ,
751 .BR u ,
752 .BR x ,
753 .B X
754 ÊÑ´¹¤Ç¤Ï¡¢É½¼¨¤µ¤ì¤ëºÇ¾®¤Î·å¿ô¤ò»ØÄꤹ¤ë¡£
755 .BR a ,
756 .BR A ,
757 .BR e ,
758 .BR E ,
759 .BR f ,
760 .B F
761 ÊÑ´¹¤Ç¤Ï¡¢¾®¿ôÅÀ°Ê²¼¤Ëɽ¼¨¤µ¤ì¤ë¿ô»ú¤Î·å¿ô¤ò»ØÄꤹ¤ë¡£
762 .B g
763 ¤È
764 .B G
765 ÊÑ´¹¤Ç¤Ï¡¢Í­¸ú¿ô»ú¤ÎºÇÂç·å¿ô¤ò»ØÄꤹ¤ë¡£
766 .B s
767 ¤È
768 .B S
769 ÊÑ´¹¤Ç¤Ï¡¢Ê¸»úÎ󤫤é½ÐÎϤµ¤ì¤ëºÇÂçʸ»ú¿ô¤ò»ØÄꤹ¤ë¡£
770 .\"O .SS "The length modifier"
771 .SS Ä¹¤µ½¤¾þ»Ò
772 .\"O Here, "integer conversion" stands for
773 .\"O .BR d ,
774 .\"O .BR i ,
775 .\"O .BR o ,
776 .\"O .BR u ,
777 .\"O .BR x ,
778 .\"O or
779 .\"O .B X
780 .\"O conversion.
781 ¡ÖÀ°¿ôÊÑ´¹¡×¤È¤Ï¡¢
782 .BR d ,
783 .BR i ,
784 .BR o ,
785 .BR u ,
786 .BR x ,
787 .B X
788 ÊÑ´¹¤Î¤³¤È¤Ç¤¢¤ë¡£
789 .TP
790 .B hh
791 .\"O A following integer conversion corresponds to a
792 .\"O .I signed char
793 .\"O or
794 .\"O .I unsigned char
795 .\"O argument, or a following
796 .\"O .B n
797 .\"O conversion corresponds to a pointer to a
798 .\"O .I signed char
799 .\"O argument.
800 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
801 .I signed char
802 ¤«
803 .I unsigned char
804 ¤Ç¡¢
805 .B n
806 ÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
807 .I signed char
808 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
809 .TP
810 .B h
811 .\"O A following integer conversion corresponds to a
812 .\"O .I short int
813 .\"O or
814 .\"O .I unsigned short int
815 .\"O argument, or a following
816 .\"O .B n
817 .\"O conversion corresponds to a pointer to a
818 .\"O .I short int
819 .\"O argument.
820 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
821 .I short int
822 ¤«
823 .I unsigned short int
824 ¤Ç¡¢
825 .B n
826 ÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
827 .I short int
828 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
829 .TP
830 .\"O .B l
831 .\"O (ell) A following integer conversion corresponds to a
832 .\"O .I long int
833 .\"O or
834 .\"O .I unsigned long int
835 .\"O argument, or a following
836 .\"O .B n
837 .\"O conversion corresponds to a pointer to a
838 .\"O .I long long int
839 .\"O argument, or a following
840 .\"O .B c
841 .\"O conversion corresponds to a
842 .\"O .I wint_t
843 .\"O argument, or a following
844 .\"O .B s
845 .\"O conversion corresponds to a pointer to
846 .\"O .I wchar_t
847 .\"O argument.
848 .BR l " (¥¨¥ë)"
849 ³ÆÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬¡¢
850 À°¿ôÊÑ´¹¤Ç¤Ï
851 .IR "long int" ¤«
852 .IR "unsigned long int" ¡¢
853 .B n
854 ÊÑ´¹¤Ç¤Ï
855 .I long long int
856 ¤Ø¤Î¥Ý¥¤¥ó¥¿¡¢
857 .B c
858 ÊÑ´¹¤Ç¤Ï
859 .IR wint_t ¡¢
860 .B s
861 ÊÑ´¹¤Ç¤Ï
862 .I wchar_t
863 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
864
865 .TP
866 .\"O .B ll
867 .\"O (ell-ell).
868 .\"O A following integer conversion corresponds to a
869 .\"O .I long long int
870 .\"O or
871 .\"O .I unsigned long long int
872 .\"O argument, or a following
873 .\"O .B n
874 .\"O conversion corresponds to a pointer to a
875 .\"O .I long int
876 .\"O argument.
877 .BR ll " (¥¨¥ë¥¨¥ë)"
878 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
879 .I long long int
880 ¤«
881 .I unsigned long long int
882 ¤Ç¡¢
883 .B n
884 ÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
885 .I long int
886 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
887 .TP
888 .B L
889 .\"O A following
890 .\"O .BR a ,
891 .\"O .BR A ,
892 .\"O .BR e ,
893 .\"O .BR E ,
894 .\"O .BR f ,
895 .\"O .BR F ,
896 .\"O .BR g ,
897 .\"O or
898 .\"O .B G
899 .\"O conversion corresponds to a
900 .\"O .I long double
901 .\"O argument.
902 .BR a ,
903 .BR A ,
904 .BR e ,
905 .BR E ,
906 .BR f ,
907 .BR F ,
908 .BR g ,
909 .B G
910 ÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
911 .I long double
912 ¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
913 .\"O (C99 allows %LF, but SUSv2 does not.)
914 (C99 ¤Ç¤Ï %LF ¤ò»È¤¦¤³¤È¤òǧ¤á¤Æ¤¤¤ë¤¬¡¢SUSv2 ¤Ç¤Ïǧ¤á¤é¤ì¤Æ¤¤¤Ê¤¤¡£)
915 .TP
916 .B q
917 .\"O ("quad". 4.4BSD and Linux libc5 only.
918 .\"O Don't use.)
919 .\"O This is a synonym for
920 .\"O .BR ll .
921 ("quad"¡£ 4.4BSD ¤È Linux libc5 ¤Î¤ßÍ­¸ú¡£»È¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£)
922 .B ll
923 ¤ÈƱ¤¸°ÕÌ£¤Ç¤¢¤ë¡£
924 .TP
925 .B j
926 .\"O A following integer conversion corresponds to an
927 .\"O .I intmax_t
928 .\"O or
929 .\"O .I uintmax_t
930 .\"O argument.
931 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
932 .I intmax_t
933 ¤«
934 .I uintmax_t
935 ¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
936 .TP
937 .B z
938 .\"O A following integer conversion corresponds to a
939 .\"O .I size_t
940 .\"O or
941 .\"O .I ssize_t
942 .\"O argument.
943 .\"O (Linux libc5 has
944 .\"O .B Z
945 .\"O with this meaning.
946 .\"O Don't use it.)
947 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
948 .I size_t
949 ¤«
950 .I ssize_t
951 ¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
952 (Linux libc5 ¤Ç¤Ï¡¢¤³¤ì¤ò»ØÄꤹ¤ë¤Î¤Ë
953 .B Z
954 ¤òÍѤ¤¤ë¡£»È¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£)
955 .TP
956 .B t
957 .\"O A following integer conversion corresponds to a
958 .\"O .I ptrdiff_t
959 .\"O argument.
960 À°¿ôÊÑ´¹¤ËÂбþ¤¹¤ë°ú¤­¿ô¤¬
961 .I ptrdiff_t
962 ¤Ç¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
963 .PP
964 .\"O The SUSv2 only knows about the length modifiers
965 .\"O .B h
966 .\"O (in
967 .\"O .BR hd ,
968 .\"O .BR hi ,
969 .\"O .BR ho ,
970 .\"O .BR hx ,
971 .\"O .BR hX ,
972 .\"O .BR hn )
973 .\"O and
974 .\"O .B l
975 .\"O (in
976 .\"O .BR ld ,
977 .\"O .BR li ,
978 .\"O .BR lo ,
979 .\"O .BR lx ,
980 .\"O .BR lX ,
981 .\"O .BR ln ,
982 .\"O .BR lc ,
983 .\"O .BR ls )
984 .\"O and
985 .\"O .B L
986 .\"O (in
987 .\"O .BR Le ,
988 .\"O .BR LE ,
989 .\"O .BR Lf ,
990 .\"O .BR Lg ,
991 .\"O .BR LG ).
992 SUSv2 ¤ÇŤµ½¤¾þ»Ò¤È¤·¤Æ»ÈÍѤǤ­¤ë¤Î¤Ï¡¢
993 .B h
994 .RB ( hd ,
995 .BR hi ,
996 .BR ho ,
997 .BR hx ,
998 .BR hX ,
999 .BR hn ),
1000 .B l
1001 .RB ( ld ,
1002 .BR li ,
1003 .BR lo ,
1004 .BR lx ,
1005 .BR lX ,
1006 .BR ln ,
1007 .BR lc ,
1008 .BR ls ),
1009 .B L
1010 .RB ( Le ,
1011 .BR LE ,
1012 .BR Lf ,
1013 .BR Lg ,
1014 .BR LG )
1015 ¤À¤±¤Ç¤¢¤ë¡£
1016 .\"O .SS "The conversion specifier"
1017 .SS ÊÑ´¹»ØÄê»Ò
1018 .\"O A character that specifies the type of conversion to be applied.
1019 ŬÍѤµ¤ì¤ëÊÑ´¹¤Î·¿¤ò»ØÄꤹ¤ëʸ»ú¡£
1020 .PP
1021 .\"O The conversion specifiers and their meanings are:
1022 ÊÑ´¹»ØÄê»Ò¤È¤½¤Î°ÕÌ£¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë¡£
1023 .TP
1024 .BR d ", " i
1025 .\"O The
1026 .\"O .I int
1027 .\"O argument is converted to signed decimal notation.
1028 .I int
1029 °ú¤­¿ô¤òÉä¹æÉÕ¤­ 10 ¿Êɽµ­¤ËÊÑ´¹¤¹¤ë¡£
1030 .\"O The precision, if any, gives the minimum number of digits
1031 .\"O that must appear; if the converted value requires fewer digits, it is
1032 .\"O padded on the left with zeros.
1033 .\"O The default precision is 1.
1034 ÀºÅÙ»ØÄ꤬¤¢¤ì¤Ð¡¢ÀºÅ٤ǻØÄꤷ¤¿·å¿ô¤Ïɬ¤º½ÐÎϤµ¤ì¤ë¡£ÊÑ´¹¸å¤ÎÃͤ¬
1035 »ØÄꤵ¤ì¤¿·å¿ô¤Ë­¤ê¤Ê¤¤¾ì¹ç¤Ï¡¢º¸Â¦¤¬ 0 ¤ÇËä¤á¤é¤ì¤ë¡£
1036 ¥Ç¥Õ¥©¥ë¥È¤ÎÀºÅ٤Ϡ1 ¤Ç¤¢¤ë¡£
1037 .\"O When 0 is printed with an explicit precision 0, the output is empty.
1038 0 ¤òɽ¼¨¤·¤è¤¦¤È¤·¤¿»þ¤Ë¡¢ÌÀ¼¨Åª¤ËÀºÅ٤Ȥ·¤Æ 0 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¤È¡¢
1039 ½ÐÎϤ϶õʸ»úÎó¤È¤Ê¤ë¡£
1040 .TP
1041 .BR o ", " u ", " x ", " X
1042 .\"O The
1043 .\"O .I "unsigned int"
1044 .\"O argument is converted to unsigned octal
1045 .\"O .RB ( o ),
1046 .\"O unsigned decimal
1047 .\"O .RB ( u ),
1048 .\"O or unsigned hexadecimal
1049 .\"O .RB ( x
1050 .\"O and
1051 .\"O .BR X )
1052 .\"O notation.
1053 .I "unsigned int"
1054 °ú¤­¿ô¤ò¡¢
1055 Éä¹æ¤Ê¤·8¿Ê¿ô
1056 .RB ( o ),
1057 Éä¹æ¤Ê¤·10¿Ê¿ô
1058 .RB ( u ),
1059 Éä¹æ¤Ê¤·16¿Ê¿ô
1060 .RB ( x
1061 ¤È
1062 .BR X )
1063 ¤ËÊÑ´¹¤¹¤ë¡£
1064 .\"O The letters
1065 .\"O .B abcdef
1066 .\"O are used for
1067 .\"O .B x
1068 .\"O conversions; the letters
1069 .\"O .B ABCDEF
1070 .\"O are used for
1071 .\"O .B X
1072 .\"O conversions.
1073 .B x
1074 ÊÑ´¹¤Ç¤Ï
1075 .B abcdef
1076 ¤¬»ÈÍѤµ¤ì¡¢
1077 .B X
1078 ÊÑ´¹¤Ç¤Ï
1079 .B ABCDEF
1080 ¤¬»ÈÍѤµ¤ì¤ë¡£
1081 .\"O The precision, if any, gives the minimum number of digits
1082 .\"O that must appear; if the converted value requires fewer digits, it is
1083 .\"O padded on the left with zeros.
1084 ÀºÅÙ»ØÄ꤬¤¢¤ì¤Ð¡¢ÀºÅ٤ǻØÄꤷ¤¿·å¿ô¤Ïɬ¤º½ÐÎϤµ¤ì¤ë¡£ÊÑ´¹¸å¤ÎÃͤ¬
1085 »ØÄꤵ¤ì¤¿·å¿ô¤Ë­¤ê¤Ê¤¤¾ì¹ç¤Ï¡¢º¸Â¦¤¬ 0 ¤ÇËä¤á¤é¤ì¤ë¡£
1086 .TP
1087 .BR e ", " E
1088 .\"O The
1089 .\"O .I double
1090 .\"O argument is rounded and converted in the style
1091 .\"O .if \w'\*(Pm'=0 .ds Pm \(+-
1092 .\"O .RB [\-]d \&. ddd e \\*(Pmdd
1093 .\"O where there is one digit before the decimal-point character and the number
1094 .\"O of digits after it is equal to the precision; if the precision is missing,
1095 .\"O it is taken as 6; if the precision is zero, no decimal-point character
1096 .\"O appears.
1097 .\"O An
1098 .I double
1099 °ú¤­¿ô¤ò´Ý¤á¤Æ
1100 .if \w'\*(Pm'=0 .ds Pm \(+-
1101 .RB [\-]d \&. ddd e \\*(Pmdd
1102 ¤Î·Á¤ËÊÑ´¹¤¹¤ë¡£
1103 ¾®¿ôÅÀ¤ÎÁ°¤Ë¤Ï°ì·å¤Î¿ô»ú¤¬¤¢¤ê¡¢¾®¿ôÅÀ°Ê²¼¤Î·å¿ô¤ÏÀºÅ٤ǻØÄꤵ¤ì¤¿
1104 ·å¿ô¤Ë¤Ê¤ë¡£ÀºÅ٤ϻØÄꤵ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç 6 ¤È¤ß¤Ê¤µ¤ì¤ë¡£
1105 ÀºÅÙ¤¬ 0 ¤Î¾ì¹ç¤Ë¤Ï¡¢¾®¿ôÅÀ°Ê²¼¤Ïɽ¼¨¤µ¤ì¤Ê¤¤¡£
1106 .\"O .B E
1107 .\"O conversion uses the letter
1108 .\"O .B E
1109 .\"O (rather than
1110 .\"O .BR e )
1111 .\"O to introduce the exponent.
1112 .B E
1113 ÊÑ´¹¤Ç¤Ï¡¢»Ø¿ô¤òɽ¸½¤¹¤ë¤È¤­¤Ë
1114 .RB ( e
1115 ¤Ç¤Ï¤Ê¤¯)
1116 .B E
1117 ¤¬»È¤ï¤ì¤ë¡£
1118 .\"O The exponent always contains at least two
1119 .\"O digits; if the value is zero, the exponent is 00.
1120 »Ø¿ôÉôʬ¤Ï¾¯¤Ê¤¯¤È¤â 2·åɽ¼¨¤µ¤ì¤ë¡£
1121 ¤Ä¤Þ¤ê¡¢»Ø¿ô¤ÎÃͤ¬ 0 ¤Î¾ì¹ç¤Ë¤Ï¡¢00 ¤Èɽ¼¨¤µ¤ì¤ë¡£
1122 .TP
1123 .BR f ", " F
1124 .\"O The
1125 .\"O .I double
1126 .\"O argument is rounded and converted to decimal notation in the style
1127 .\"O .RB [\-]ddd \&. ddd,
1128 .\"O where the number of digits after the decimal-point character is equal to
1129 .\"O the precision specification.
1130 .I double
1131 °ú¤­¿ô¤ò´Ý¤á¤Æ
1132 .RB [\-]ddd \&. ddd
1133 ¤Î·Á¤Î10¿Êɽ¸½¤ËÊÑ´¹¤¹¤ë¡£
1134 ¾®¿ôÅÀ¤Î¸å¤Î·å¿ô¤Ï¡¢ÀºÅ٤ǻØÄꤵ¤ì¤¿ÃͤȤʤ롣
1135 .\"O If the precision is missing, it is taken as
1136 .\"O 6; if the precision is explicitly zero, no decimal-point character appears.
1137 ÀºÅÙ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï 6 ¤È¤·¤Æ°·¤ï¤ì¤ë¡£
1138 ÀºÅ٤Ȥ·¤ÆÌÀ¼¨Åª¤Ë 0 ¤¬»ØÄꤵ¤ì¤¿¤È¤­¤Ë¤Ï¡¢¾®¿ôÅÀ°Ê²¼¤Ïɽ¼¨¤µ¤ì¤Ê¤¤¡£
1139 .\"O If a decimal point appears, at least one digit appears before it.
1140 ¾®¿ôÅÀ¤òɽ¼¨¤¹¤ëºÝ¤Ë¤Ï¡¢¾®¿ôÅÀ¤ÎÁ°¤Ë¾¯¤Ê¤¯¤È¤â°ì·å¤Ï¿ô»ú¤¬É½¼¨¤µ¤ì¤ë¡£
1141
1142 .\"O (The SUSv2 does not know about
1143 .\"O .B F
1144 .\"O and says that character string representations for infinity and NaN
1145 .\"O may be made available.
1146 .\"O The C99 standard specifies "[\-]inf" or "[\-]infinity"
1147 .\"O for infinity, and a string starting with "nan" for NaN, in the case of
1148 .\"O .B f
1149 .\"O conversion, and "[\-]INF" or "[\-]INFINITY" or "NAN*" in the case of
1150 .\"O .B F
1151 .\"O conversion.)
1152 (SUSv2 ¤Ç¤Ï¡¢
1153 .B F
1154 ¤Ïµ¬Äꤵ¤ì¤Æ¤ª¤é¤º¡¢Ìµ¸Â¤ä NaN ¤Ë´Ø¤¹¤ëʸ»úÎóɽ¸½¤ò
1155 ¹Ô¤Ã¤Æ¤â¤è¤¤¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
1156  C99 É¸½à¤Ç¤Ï¡¢
1157 .B f
1158 ÊÑ´¹¤Ç¤Ï¡¢Ìµ¸Â¤Ï "[\-]inf" ¤« "[\-]infinity" ¤Èɽ¼¨¤·¡¢
1159 NaN ¤Ïʸ»úÎó¤ÎÀèƬ¤Ë `nan' ¤ò¤Ä¤±¤Æɽ¼¨¤¹¤ë¤è¤¦¤Ëµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£
1160 .B F
1161 ÊÑ´¹¤Î¾ì¹ç¤Ï "[\-]INF", "[\-]INFINITY", "NAN*" ¤Èɽ¼¨¤µ¤ì¤ë¡£)
1162 .TP
1163 .BR g ", " G
1164 .\"O The
1165 .\"O .I double
1166 .\"O argument is converted in style
1167 .\"O .B f
1168 .\"O or
1169 .\"O .B e
1170 .\"O (or
1171 .\"O .B F
1172 .\"O or
1173 .\"O .B E
1174 .\"O for
1175 .\"O .B G
1176 .\"O conversions).
1177 .I double
1178 °ú¤­¿ô¤ò
1179 .B f
1180 ¤«
1181 .B e
1182 .RB ( G
1183 ÊÑ´¹¤Î¾ì¹ç¤Ï
1184 .B F
1185 ¤«
1186 .BR E )
1187 ¤Î·Á¼°¤ËÊÑ´¹¤¹¤ë¡£
1188 .\"O The precision specifies the number of significant digits.
1189 ÀºÅÙ¤Ïɽ¼¨¤¹¤ë·å¿ô¤ò»ØÄꤹ¤ë¡£
1190 .\"O If the precision is missing, 6 digits are given; if the precision is zero,
1191 .\"O it is treated as 1.
1192 ÀºÅÙ¤¬»ØÄꤵ¤ì¤Ê¤¤¾ì¹ç¤Ï¡¢6·å¤È¤ß¤Ê¤µ¤ì¤ë¡£
1193 ÀºÅÙ¤¬ 0 ¤Î¾ì¹ç¤Ï¡¢1·å¤È¤ß¤Ê¤µ¤ì¤ë¡£
1194 .\"O Style
1195 .\"O .B e
1196 .\"O is used if the exponent from its conversion is less than \-4 or greater
1197 .\"O than or equal to the precision.
1198 ÊÑ´¹¤µ¤ì¤ëÃͤλؿô¤¬¡¢ \-4 ¤è¤ê¾®¤µ¤¤¤«¡¢ÀºÅٰʾå¤Î¾ì¹ç¤Ë¡¢
1199 .B e
1200 ·Á¼°¤¬»ÈÍѤµ¤ì¤ë¡£
1201 .\"O Trailing zeros are removed from the
1202 .\"O fractional part of the result; a decimal point appears only if it is
1203 .\"O followed by at least one digit.
1204 ÊÑ´¹¤µ¤ì¤¿·ë²Ì¤Î¾®¿ôÉôʬ¤ÎËöÈø¤Î 0 ¤Ïºï½ü¤µ¤ì¤ë¡£¾®¿ôÅÀ¤¬É½¼¨¤µ¤ì¤ë¤Î¤Ï¡¢
1205 ¾®¿ôÅÀ°Ê²¼¤Ë¿ô»ú¤¬¾¯¤Ê¤¯¤È¤â°ì¤Ä¤¢¤ë¾ì¹ç¤Ë¤À¤±¤Ç¤¢¤ë¡£
1206 .TP
1207 .BR a ", " A
1208 .\"O (C99; not in SUSv2) For
1209 .\"O .B a
1210 .\"O conversion, the
1211 .\"O .I double
1212 .\"O argument is converted to hexadecimal notation (using the letters abcdef)
1213 .\"O in the style
1214 .\"O .RB [\-] 0x h \&. hhhh p \\*(Pmd;
1215 .\"O for
1216 .\"O .B A
1217 .\"O conversion the prefix
1218 .\"O .BR 0X ,
1219 .\"O the letters ABCDEF, and the exponent separator
1220 .\"O .B P
1221 .\"O is used.
1222 (C99 ¤Ë¤Ï¤¢¤ë¤¬ SUSv2 ¤Ë¤Ï¤Ê¤¤)
1223 .B a
1224 ÊÑ´¹¤Ç¤Ï¡¢
1225 .I double
1226 °ú¤­¿ô¤ò (abcdef ¤Îʸ»ú¤ò»È¤Ã¤Æ)
1227 .RB [\-] 0x h \&. hhhh p \\*(Pmd;
1228 ·Á¼°¤Î 16 ¿Êɽµ­¤ËÊÑ´¹¤¹¤ë¡£
1229 .B A
1230 ÊÑ´¹¤Ç¤Ï¡¢Á°ÃÖʸ»úÎó
1231 .BR 0X ,
1232 ʸ»ú ABCDEF, »Ø¿ôʸ»ú
1233 .B P
1234 ¤òÍѤ¤¤ë¡£
1235 .\"O There is one hexadecimal digit before the decimal point,
1236 .\"O and the number of digits after it is equal to the precision.
1237 ¾®¿ôÅÀ¤ÎÁ°¤Ë¤Ï 1·å¤Î16¿Ê¿ô¤¬ÃÖ¤«¤ì¡¢¾®¿ôÅÀ¤Î¸å¤í¤Î·å¿ô¤Ï
1238 ÀºÅ٤ǻØÄꤵ¤ì¤¿ÃͤȤʤ롣
1239 .\"O The default precision suffices for an exact representation of the value
1240 .\"O if an exact representation in base 2 exists
1241 .\"O and otherwise is sufficiently large to distinguish values of type
1242 .\"O .IR double .
1243 ¥Ç¥Õ¥©¥ë¥È¤ÎÀºÅ٤ϡ¢¤½¤ÎÃͤ¬ 2¿Ê¿ô¤ÇÀµ³Î¤Ëɽ¸½¤Ç¤­¤ë¾ì¹ç¤Ë¤Ï¡¢
1244 ¤½¤ÎÃͤòÀµ³Î¤Ëɽ¸½¤Ç¤­¤ë·å¿ô¤È¤Ê¤ë¡£¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¡¢
1245 .I double
1246 ·¿¤ÎÃͤò¶èÊ̤¹¤ë¤Î¤Ë½½Ê¬¤ÊÂ礭¤µ¤È¤Ê¤ë¡£
1247 .\"O The digit before the decimal point is unspecified for nonnormalized
1248 .\"O numbers, and nonzero but otherwise unspecified for normalized numbers.
1249 .\" motoki 2005/03/19: ¹ç¤Ã¤Æ¤¤¤ë¤«¤Ê¡©
1250 ¾®¿ôÅÀ¤ÎÁ°¤Î¿ô»ú¤Ï¡¢Àµµ¬²½¤µ¤ì¤Æ¤¤¤Ê¤¤¿ô¤Î¾ì¹ç¤Ï¤¤¤¯¤Ä¤Ë¤Ê¤ë¤«Ê¬¤«¤é¤Ê¤¤¡£
1251 Àµµ¬²½¤µ¤ì¤¿¿ô¤Î¾ì¹ç¤Ï¡¢ 0 °Ê³°¤ÎÃͤˤʤ뤬¡¢¤¤¤¯¤Ä¤Ë¤Ê¤ë¤«¤Ïʬ¤«¤é¤Ê¤¤¡£
1252 .TP
1253 .B c
1254 .\"O If no
1255 .\"O .B l
1256 .\"O modifier is present, the
1257 .\"O .I int
1258 .\"O argument is converted to an
1259 .\"O .IR "unsigned char" ,
1260 .\"O and the resulting character is written.
1261 .B l
1262 ½¤¾þ»Ò¤¬¤Ê¤±¤ì¤Ð¡¢
1263 .I int
1264 °ú¤­¿ô¤ò
1265 .IR "unsigned char"
1266 ¤ËÊÑ´¹¤·¤Æ¡¢¤½¤Î·ë²Ì¤ËÂбþ¤¹¤ëʸ»ú¤ò½ÐÎϤ¹¤ë¡£
1267 .\"O If an
1268 .\"O .B l
1269 .\"O modifier is present, the
1270 .\"O .I wint_t
1271 .\"O (wide character) argument is converted to a multibyte sequence by a call
1272 .\"O to the
1273 .\"O .BR wcrtomb (3)
1274 .\"O function, with a conversion state starting in the initial state, and the
1275 .\"O resulting multibyte string is written.
1276 .B l
1277 ½¤¾þ»Ò¤¬¤¢¤ì¤Ð¡¢
1278 .I wint_t
1279 (¥ï¥¤¥Éʸ»ú) °ú¤­¿ô¤ò¡¢
1280 .BR wcrtomb (3)
1281 ´Ø¿ô¤ò½é´ü¥·¥Õ¥È¾õÂ֤ǸƤӽФ·¤Æ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎó¤ËÊÑ´¹¤·¡¢
1282 ÊÑ´¹¤µ¤ì¤¿¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎó¤ò½ÐÎϤ¹¤ë¡£
1283 .TP
1284 .B s
1285 .\"O If no
1286 .\"O .B l
1287 .\"O modifier is present: The
1288 .\"O .I "const char *"
1289 .\"O argument is expected to be a pointer to an array of character type (pointer
1290 .\"O to a string).
1291 .\"O Characters from the array are written up to (but not
1292 .\"O including) a terminating null byte (\(aq\\0\(aq);
1293 .\"O if a precision is specified, no more than the number specified
1294 .\"O are written.
1295 .\"O If a precision is given, no null byte need be present;
1296 .\"O if the precision is not specified, or is greater than the size of the
1297 .\"O array, the array must contain a terminating null byte.
1298 .B l
1299 ½¤¾þ»Ò¤¬¤Ê¤¤¾ì¹ç¡¢
1300 °ú¤­¿ô¤Ï
1301 .I "const char *"
1302 ·¿¤Çʸ»ú·¿¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿ (ʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿) ¤Ç¤¢¤ë¤³¤È¤¬
1303 ´üÂÔ¤µ¤ì¤Æ¤¤¤ë¡£ÇÛÎóÃæ¤Îʸ»ú¤Ï¡¢½ªÃ¼¤Î NULL ¥Ð¥¤¥È (\(aq\\0\(aq)
1304 ¤¬½Ð¤Æ¤¯¤ë¤Þ¤Ç½ÐÎϤµ¤ì¤ë (½ªÃ¼Ê¸»ú¤Ï½ÐÎϤµ¤ì¤Ê¤¤)¡£
1305 ÀºÅÙ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¤È¡¢»ØÄꤵ¤ì¤¿»ú¿ô°Ê¾å¤Ï½ÐÎϤµ¤ì¤Ê¤¤¡£
1306 ÀºÅÙ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢½ªÃ¼¥Ð¥¤¥È¤¬Â¸ºß¤¹¤ëɬÍפϤʤ¤¡£
1307 ÀºÅÙ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¤ê¡¢ÀºÅÙ¤ÎÃͤ¬ÇÛÎó¤ÎÂ礭¤µ¤è¤êÂ礭¤¤¾ì¹ç¤Ë¤Ï¡¢
1308 ÇÛÎó¤Ï½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤ò´Þ¤ó¤Ç¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
1309
1310 .\"O If an
1311 .\"O .B l
1312 .\"O modifier is present: The
1313 .\"O .I "const wchar_t *"
1314 .\"O argument is expected to be a pointer to an array of wide characters.
1315 .B l
1316 ½¤¾þ»Ò¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢
1317 °ú¤­¿ô¤Ï
1318 .I "const wchar_t *"
1319 ·¿¤Ç¥ï¥¤¥Éʸ»ú¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¤³¤È¤¬´üÂÔ¤µ¤ì¤Æ¤¤¤ë¡£
1320 .\"O Wide characters from the array are converted to multibyte characters
1321 .\"O (each by a call to the
1322 .\"O .BR wcrtomb (3)
1323 .\"O function, with a conversion state starting in the initial state before
1324 .\"O the first wide character), up to and including a terminating null
1325 .\"O wide character.
1326 .\"O The resulting multibyte characters are written up to
1327 .\"O (but not including) the terminating null byte.
1328 .\"O If a precision is
1329 .\"O specified, no more bytes than the number specified are written, but
1330 .\"O no partial multibyte characters are written.
1331 .\"O Note that the precision
1332 .\"O determines the number of
1333 .\"O .I bytes
1334 .\"O written, not the number of
1335 .\"O .I wide characters
1336 .\"O or
1337 .\"O .IR "screen positions" .
1338 ÇÛÎóÃæ¤Î¥ï¥¤¥Éʸ»ú¤Ï (1ʸ»úËè¤Ë
1339 .BR wcrtomb (3)
1340 ¤ò¸Æ¤Ó½Ð¤·¤Æ) ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»ú¤ËÊÑ´¹¤µ¤ì¤ë
1341 (ºÇ½é¤Î¥ï¥¤¥Éʸ»ú¤ÎÊÑ´¹¤ÎÁ°¤Ë
1342 .BR wcrtomb ()
1343 ¤Î¥·¥Õ¥È¾õÂÖ¤ò½é´ü¾õÂÖ¤ËÌᤷ¤Æ¤«¤éÊÑ´¹¤Ï¹Ô¤ï¤ì¤ë)¡£
1344 ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»ú¤Ø¤ÎÊÑ´¹¤Ï¡¢Ê¸»úÎó¤ò½ªÃ¼¤¹¤ë NULL ¥ï¥¤¥Éʸ»ú¤¬
1345 ½Ð¤Æ¤¯¤ë¤Þ¤Ç¹Ô¤ï¤ì¡¢½ªÃ¼ NULL ¥ï¥¤¥Éʸ»ú¤â´Þ¤á¤ÆÊÑ´¹¤µ¤ì¤ë¡£
1346 ·ë²Ì¤Î¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»úÎó¤Ï¡¢½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤¬½Ð¤Æ¤¯¤ë¤Þ¤Ç
1347 ½ÐÎϤµ¤ì¤ë (½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï½ÐÎϤµ¤ì¤Ê¤¤)¡£
1348 ÀºÅÙ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢»ØÄꤵ¤ì¤¿¥Ð¥¤¥È¿ô°Ê¾å¤Ë¤Ï½ÐÎϤµ¤ì¤Ê¤¤¡£
1349 ⤷¡¢¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»ú¤Î°ìÉôʬ¤À¤±¤¬½ÐÎϤµ¤ì¤ë¤³¤È¤Ï¤Ê¤¤¡£
1350 ÀºÅ٤ϡ֥Х¤¥È¡×¿ô¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¤¢¤ê¡¢¡Ö¥ï¥¤¥Éʸ»ú¡×¿ô¤ä
1351 ¡Ö²èÌ̤ǤΰÌÃ֡פò»ØÄꤹ¤ë¤â¤Î¤Ç¤Ï¤Ê¤¤¤³¤È¤ËÃí°Õ¡£
1352 .\"O The array must contain a terminating null wide character, unless a
1353 .\"O precision is given and it is so small that the number of bytes written
1354 .\"O exceeds it before the end of the array is reached.
1355 ÀºÅÙ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Æ¡¢¤µ¤é¤Ë½ÐÎϤ¬ÇÛÎó¤ÎËöÈø¤Ë㤹¤ëÁ°¤Ë½ÐÎϥХ¤¥È¿ô¤¬
1356 ÀºÅÙ¤ÎÃͤòĶ¤¨¤ë¾ì¹ç¤À¤±¤Ï¡¢ÇÛÎó¤Ï NULL ¥ï¥¤¥Éʸ»ú¤Ç½ªÃ¼¤µ¤ì¤Æ¤¤¤Ê¤¯¤Æ¤â¤è¤¤¡£
1357 ¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¡¢É¬¤ºÇÛÎó¤Ï NULL ¥ï¥¤¥Éʸ»ú¤Ç½ªÃ¼¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
1358 .TP
1359 .B C
1360 .\"O (Not in C99, but in SUSv2.)
1361 .\"O Synonym for
1362 .\"O .BR lc .
1363 .\"O Don't use.
1364 (C99 ¤Ë¤Ï¤Ê¤¤¤¬ SUSv2 ¤Ë¤Ï¤¢¤ë)
1365 .B lc
1366 ¤ÈƱ¤¸¡£»È¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
1367 .TP
1368 .B S
1369 .\"O (Not in C99, but in SUSv2.)
1370 .\"O Synonym for
1371 .\"O .BR ls .
1372 .\"O Don't use.
1373 (C99 ¤Ë¤Ï¤Ê¤¤¤¬ SUSv2 ¤Ë¤Ï¤¢¤ë)
1374 .B ls
1375 ¤ÈƱ¤¸¡£»È¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
1376 .TP
1377 .B p
1378 .\"O The
1379 .\"O .I "void *"
1380 .\"O pointer argument is printed in hexadecimal (as if by
1381 .\"O .B %#x
1382 .\"O or
1383 .\"O .BR  %#lx ).
1384 .I "void *"
1385 ¥Ý¥¤¥ó¥¿°ú¤­¿ô¤ò
1386 .RB ( %#x
1387 ¤ä
1388 .BR  %#lx
1389 ¤Î¤è¤¦¤Ê) 16 ¿Ê¿ô¤Ç½ÐÎϤ¹¤ë¡£
1390 .TP
1391 .B n
1392 .\"O The number of characters written so far is stored into the integer
1393 .\"O indicated by the
1394 .\"O .I "int *"
1395 .\"O (or variant) pointer argument.
1396 .\"O No argument is converted.
1397 ¤³¤ì¤Þ¤Ç¤Ë½ÐÎϤµ¤ì¤¿Ê¸»ú¿ô¤ò
1398 .I "int *"
1399 (¤Þ¤¿¤ÏÎà»÷¤Î·¿) ¤Î¥Ý¥¤¥ó¥¿°ú¤­¿ô¤¬»Ø¤¹À°¿ô¤ËÊݸ¤¹¤ë¡£
1400 °ú¤­¿ô¤ÎÊÑ´¹¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£
1401 .TP
1402 .B m
1403 .\"O (Glibc extension.)
1404 .\"O Print output of
1405 .\"O .IR strerror(errno) .
1406 .\"O No argument is required.
1407 (glibc ¤Ç¤Î³ÈÄ¥)
1408 .I strerror(errno)
1409 ¤Î½ÐÎϤòɽ¼¨¤¹¤ë¡£°ú¤­¿ô¤ÏɬÍפʤ¤¡£
1410 .TP
1411 .B %
1412 .\"O A \(aq%\(aq is written.
1413 .\"O No argument is converted.
1414 .\"O The complete conversion
1415 .\"O specification is \(aq%%\(aq.
1416 \(aq%\(aq Ê¸»ú¤ò½ÐÎϤ¹¤ë¡£ÊÑ´¹¤µ¤ì¤ë°ú¤­¿ô¤Ï̵¤¤¡£
1417 ÊÑ´¹»ØÄêÁ´ÂΤò½ñ¤¯¤È "%%" ¤È¤Ê¤ë¡£
1418 .\"O .SH "CONFORMING TO"
1419 .SH ½àµò
1420 .\"O The
1421 .\"O .BR fprintf (),
1422 .\"O .BR printf (),
1423 .\"O .BR sprintf (),
1424 .\"O .BR vprintf (),
1425 .\"O .BR vfprintf (),
1426 .\"O and
1427 .\"O .BR vsprintf ()
1428 .\"O functions conform to C89 and C99.
1429 .BR fprintf (),
1430 .BR printf (),
1431 .BR sprintf (),
1432 .BR vprintf (),
1433 .BR vfprintf (),
1434 .BR vsprintf ()
1435 ´Ø¿ô¤Ï¡¢C89 ¤È C99 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
1436 .\"O The
1437 .\"O .BR snprintf ()
1438 .\"O and
1439 .\"O .BR vsnprintf ()
1440 .\"O functions conform to C99.
1441 .BR snprintf ()
1442 ¤È
1443 .BR vsnprintf ()
1444 ¤Ï C99 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
1445 .PP
1446 .\"O Concerning the return value of
1447 .\"O .BR snprintf (),
1448 .\"O SUSv2 and C99 standard contradict each other: when
1449 .\"O .BR snprintf ()
1450 .\"O is called with
1451 .\"O .IR size =0
1452 .\"O then SUSv2 stipulates an unspecified return value less than 1,
1453 .\"O while C99 allows
1454 .\"O .I str
1455 .\"O to be NULL in this case, and gives the return value (as always)
1456 .\"O as the number of characters that would have been written in case
1457 .\"O the output string has been large enough.
1458 .BR snprintf ()
1459 ¤ÎÊÖ¤êÃͤò¸«¤ë¤È¡¢
1460 SUSv2 ¤È C99 É¸½à¤Ï¸ß¤¤¤ËÌ·½â¤·¤Æ¤¤¤ë¡£
1461 SUSv2 ¤Ç¤Ï¡¢
1462 .BR snprintf ()
1463 ¤¬
1464 .IR size =0
1465 ¤Ç¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¡¢ 1 Ì¤Ëþ¤ÎÃͤò²¿¤«ÊÖ¤êÃͤȤ¹¤ë¤è¤¦¤Ëµ¬Äꤷ¤Æ¤¤¤ë¡£
1466 °ìÊý C99 ¤Ç¤Ï¡¢¤³¤Î¤è¤¦¤Ê¾ì¹ç
1467 .I str
1468 ¤ò NULL ¤È¤·¡¢ÊÖ¤êÃͤȤ·¤Æ (Ä̾ïÄ̤ê) ½ÐÎϥХåե¡¤¬½½Ê¬¤ÊÂ礭¤µ¤¬
1469 ¤¢¤Ã¤¿¾ì¹ç¤Ë½ÐÎϤµ¤ì¤ë¤Ç¤¢¤í¤¦Ê¸»ú¿ô¤òÊÖ¤¹¡£
1470 .PP
1471 .\"O Linux libc4 knows about the five C standard flags.
1472 .\"O It knows about the length modifiers \fBh\fP, \fBl\fP, \fBL\fP,
1473 .\"O and the conversions
1474 .\"O \fBc\fP, \fBd\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP,
1475 .\"O \fBg\fP, \fBG\fP, \fBi\fP, \fBn\fP, \fBo\fP, \fBp\fP,
1476 .\"O \fBs\fP, \fBu\fP, \fBx\fP, and \fBX\fP,
1477 .\"O where \fBF\fP is a synonym for \fBf\fP.
1478 Linux libc4 ¤Ç¤Ï¡¢ 5 ¤Ä¤Î C É¸½à¤Î¥Õ¥é¥°¡¢
1479 Ťµ½¤¾þ»Ò \fBh\fP, \fBl\fP, \fBL\fP¡¢ÊÑ´¹
1480 \fBc\fP, \fBd\fP, \fBe\fP, \fBE\fP, \fBf\fP, \fBF\fP,
1481 \fBg\fP, \fBG\fP, \fBi\fP, \fBn\fP, \fBo\fP, \fBp\fP,
1482 \fBs\fP, \fBu\fP, \fBx\fP, \fBX\fP
1483 ¤¬»È¤¨¤ë¡£
1484 ⤷ \fBF\fP ¤Ï \fBf\fP ¤ÈƱµÁ¤Ç¤¢¤ë¡£
1485 .\"O Additionally, it accepts \fBD\fP, \fBO\fP, and \fBU\fP as synonyms
1486 .\"O for \fBld\fP, \fBlo\fP, and \fBlu\fP.
1487 .\"O (This is bad, and caused serious bugs later, when
1488 .\"O support for \fB%D\fP disappeared.)
1489 .\"O No locale-dependent radix character,
1490 .\"O no thousands' separator, no NaN or infinity, no "%m$" and "*m$".
1491 ¤Þ¤¿¡¢ \fBD\fP, \fBO\fP, and \fBU\fP ¤ò \fBld\fP, \fBlo\fP, and \fBlu\fP
1492 ¤ÈƱ¤¸¤â¤Î¤È¤·¤Æ»È¤¨¤ë
1493 (¤³¤ì¤Ï¤Þ¤º¤¤»ÅÍͤǡ¢ ¸å¤Ë \fB%D\fP ¤ÎÂбþ¤¬ÂǤÁÀÚ¤é¤ì¤¿»þ¤Ë¿¼¹ï¤Ê¥Ð¥°¤ò
1494 °ú¤­µ¯¤³¤·¤¿)¡£¥í¥±¡¼¥ë°Í¸¤Î¾®¿ôÅÀ¡¢1000 ¶èÀڤꡢ NaN ¤È̵¸Â¡¢
1495 "%m$" ¤È "*m$" ¤Ï»È¤¨¤Ê¤¤¡£
1496 .PP
1497 .\"O Linux libc5 knows about the five C standard flags and the \(aq flag,
1498 .\"O locale, "%m$" and "*m$".
1499 .\"O It knows about the length modifiers \fBh\fP, \fBl\fP, \fBL\fP,
1500 .\"O \fBZ\fP, and \fBq\fP, but accepts \fBL\fP and \fBq\fP
1501 .\"O both for \fIlong double\fP and for \fIlong long int\fP (this is a bug).
1502 Linux libc5 ¤Ç¤Ï¡¢ 5 ¤Ä¤Î C É¸½à¤Î¥Õ¥é¥°¤È \(aq ¥Õ¥é¥°¡¢¥í¥±¡¼¥ë¡¢
1503 "%m$" ¤È "*m$" ¤¬»È¤¨¤ë¡£
1504 ¤Þ¤¿¡¢Ä¹¤µ½¤¾þ»Ò \fBh\fP, \fBl\fP, \fBL\fP, \fBZ\fP, iand \fBq\fP ¤¬»È¤¨¤ë¤¬¡¢
1505 \fBL\fP ¤È \fBq\fP ¤ÏξÊý¤È¤â
1506 \fIlong double\fP ¤È \fIlong long int\fP ¤ËÂбþ¤·¤Æ¤¤¤ë (¤³¤ì¤Ï¥Ð¥°¤Ç¤¢¤ë)¡£
1507 .\"O It no longer recognizes \fBF\fP, \fBD\fP, \fBO\fP, and \fBU\fP,
1508 .\"O but adds the conversion character
1509 .\"O .BR m ,
1510 .\"O which outputs
1511 .\"O .IR strerror(errno) .
1512 ¸½ºß¤Ç¤ÏÊÑ´¹ \fBF\fP, \fBD\fP, \fBO\fP, \fBU\fP ¤Ïǧ¼±¤µ¤ì¤Ê¤¤¤¬¡¢ÊÑ´¹Ê¸»ú
1513 .B m
1514 ¤¬Äɲ䵤줿¡£¤³¤ì¤Ï
1515 .I strerror(errno)
1516 ¤ò½ÐÎϤ¹¤ë¤â¤Î¤Ç¤¢¤ë¡£
1517 .PP
1518 .\"O glibc 2.0 adds conversion characters \fBC\fP and \fBS\fP.
1519 glibc 2.0 ¤Ç¤Ï¡¢ÊÑ´¹Ê¸»ú \fBC\fP ¤È \fBS\fP ¤¬Äɲ䵤줿¡£
1520 .PP
1521 .\"O glibc 2.1 adds length modifiers \fBhh\fP, \fBj\fP, \fBt\fP, and \fBz\fP
1522 .\"O and conversion characters \fBa\fP and \fBA\fP.
1523 glibc 2.1 ¤Ç¤Ï¡¢Ä¹¤µ½¤¾þ»Ò \fBhh\fP, \fBj\fP, \fBt\fP, \fBz\fP
1524 ¤ÈÊÑ´¹Ê¸»ú \fBa\fP, \fBA\fP ¤¬Äɲ䵤줿¡£
1525 .PP
1526 .\"O glibc 2.2 adds the conversion character \fBF\fP with C99 semantics,
1527 .\"O and the flag character \fBI\fP.
1528 glibc 2.2 ¤Ç¤Ï¡¢ C99 ¤Çµ¬Äꤵ¤ì¤¿°ÕÌ£¤Ç¤ÎÊÑ´¹Ê¸»ú \fBF\fP ¤È
1529 ¥Õ¥é¥°Ê¸»ú \fBI\fP ¤¬Äɲ䵤줿¡£
1530 .\"O .SH NOTES
1531 .SH Ãí°Õ
1532 .\"O Some programs imprudently rely on code such as the following
1533 .\"O 
1534 .\"O     sprintf(buf, "%s some further text", buf);
1535 .\"O 
1536 .\"O to append text to
1537 .\"O .IR buf .
1538 ¥Æ¥­¥¹¥È¤ò
1539 .I buf
1540 ¤ËÄɲ乤ë¤Î¤Ë¡¢·ÚΨ¤Ë¤â¼¡¤Î¤è¤¦¤Ê¥³¡¼¥É¤ò»È¤Ã¤Æ¤¤¤ë¥×¥í¥°¥é¥à¤¬¤¢¤ë¡£
1541
1542     sprintf(buf, "%s some further text", buf);
1543
1544 .\"O However, the standards explicitly note that the results are undefined
1545 .\"O if source and destination buffers overlap when calling
1546 .\"O .BR sprintf (),
1547 .\"O .BR snprintf (),
1548 .\"O .BR vsprintf (),
1549 .\"O and
1550 .\"O .BR vsnprintf ().
1551 ¤·¤«¤·¤Ê¤¬¤é¡¢É¸½àµ¬³Ê¤Ç¤Ï¡¢
1552 .BR sprintf (),
1553 .BR snprintf (),
1554 .BR vsprintf (),
1555 .BR vsnprintf ()
1556 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤ª¤¤¤Æ¡¢¥³¥Ô¡¼¸µ¤È¥³¥Ô¡¼Àè¤Î¥Ð¥Ã¥Õ¥¡¤¬½Å¤Ê¤Ã¤Æ¤¤¤¿¾ì¹ç¤Î
1557 ·ë²Ì¤ÏÉÔÄê¤Ç¤¢¤ë¡¢¤ÈÌÀµ­¤µ¤ì¤Æ¤¤¤ë¡£
1558 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=7075
1559 .\"O Depending on the version of
1560 .\"O .BR gcc (1)
1561 .\"O used, and the compiler options employed, calls such as the above will
1562 .\"O .B not
1563 .\"O produce the expected results.
1564 »ÈÍѤ¹¤ë
1565 .BR gcc (1)
1566 ¤Î¥Ð¡¼¥¸¥ç¥ó¤ä»ØÄꤷ¤¿¥³¥ó¥Ñ¥¤¥é¤Î¥ª¥×¥·¥ç¥ó¼¡Âè¤Ç¤Ï¡¢
1567 ¾åµ­¤Î¤è¤¦¤Ê¸Æ¤Ó½Ð¤·¤Ç¡¢´üÂÔ¤·¤¿·ë²Ì¤¬ÆÀ¤é¤ì¡Ö¤Ê¤¤¡×¤³¤È¤¬¤¢¤ë¡£
1568
1569 .\"O The glibc implementation of the functions
1570 .\"O .BR snprintf ()
1571 .\"O and
1572 .\"O .BR vsnprintf ()
1573 .\"O conforms to the C99 standard, that is, behaves as described above,
1574 .\"O since glibc version 2.1.
1575 .\"O Until glibc 2.0.6 they would return \-1
1576 .\"O when the output was truncated.
1577 glibc ¤Î
1578 .BR snprintf ()
1579 ¤È
1580 .BR vsnprintf ()
1581 ¤Î¼ÂÁõ¤Ï¡¢¥Ð¡¼¥¸¥ç¥ó 2.1 °Ê¹ß¤Ï C99 É¸½à¤Ë½àµò¤·¤Æ¤ª¤ê¡¢
1582 ¾åµ­¤ÎÄ̤ê¤ÎÆ°ºî¤ò¤¹¤ë¡£
1583 glibc 2.0.6 ¤Þ¤Ç¤Ï¡¢½ÐÎϤ¬ÀÚ¤êµÍ¤á¤é¤ì¤¿¾ì¹ç¤Ï \-1 ¤òÊÖ¤¹¡£
1584 .\"O .\" .SH HISTORY
1585 .\" .SH Îò»Ë
1586 .\"O .\" UNIX V7 defines the three routines
1587 .\"O .\" .BR printf (),
1588 .\"O .\" .BR fprintf (),
1589 .\"O .\" .BR sprintf (),
1590 .\"O .\" and has the flag \-, the width or precision *, the length modifier l,
1591 .\"O .\" and the conversions doxfegcsu, and also D,O,U,X as synonyms for ld,lo,lu,lx.
1592 .\" UNIX V7 ¤Ç¤Ï
1593 .\" .BR printf (),
1594 .\" .BR fprintf (),
1595 .\" .BR sprintf ()
1596 .\" ¤Î 3 ¤Ä¤Î´Ø¿ô¤È¡¢¥Õ¥é¥° \-¡¢Éý¤ÈÀºÅ٤ǤΠ*¡¢Ä¹¤µ½¤¾þ»Ò l¡¢
1597 .\" ÊÑ´¹ doxfegcsu¡¢¤½¤·¤Æ ld,ld,lu,lx ¤ÎƱµÁ¸ì¤È¤·¤Æ D,O,U,X ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
1598 .\"O .\" This is still true for 2.9.1BSD, but 2.10BSD has the flags
1599 .\"O .\" #, + and <space> and no longer mentions D,O,U,X.
1600 .\" 2.9.1BSD ¤Ç¤â¤³¤ì¤ÏƱ¤¸¤À¤Ã¤¿¤¬¡¢ 2.10BSD ¤Ç¤Ï
1601 .\" ¥Õ¥é¥° #, +, ¶õÇò¤¬Äɲ䵤졢 D,O,U,X ¤Ë¤Ä¤¤¤Æ¤Ïµ­ºÜ¤µ¤ì¤Ê¤¯¤Ê¤Ã¤¿¡£
1602 .\"O .\" 2.11BSD has
1603 .\"O .\" .BR vprintf (),
1604 .\"O .\" .BR vfprintf (),
1605 .\"O .\" .BR vsprintf (),
1606 .\"O .\" and warns not to use D,O,U,X.
1607 .\" 2.11BSD ¤Ç¤Ï
1608 .\" .BR vprintf (),
1609 .\" .BR vfprintf (),
1610 .\" .BR vsprintf ()
1611 .\" ¤¬Äɲ䵤졢 D,O,U,X ¤ò»È¤ï¤Ê¤¤¤è¤¦¤Ë·Ù¹ð¤µ¤ì¤¿¡£
1612 .\"O .\" 4.3BSD Reno has the flag 0, the length modifiers h and L,
1613 .\"O .\" and the conversions n, p, E, G, X (with current meaning)
1614 .\"O .\" and deprecates D,O,U.
1615 .\" 4.3BSD Reno ¤Ç¤Ï¥Õ¥é¥° 0¡¢Ä¹¤µ½¤¾þ»Ò h ¤È L¡¢
1616 .\" ÊÑ´¹ n, p, E, G, (¸½ºß¤Î°ÕÌ£¤Ç¤Î) X ¤¬Äɲ䵤졢
1617 .\" D,O,U ¤ÏÈó¿ä¾©°·¤¤¤È¤Ê¤Ã¤¿¡£
1618 .\"O .\" 4.4BSD introduces the functions
1619 .\"O .\" .BR snprintf ()
1620 .\"O .\" and
1621 .\"O .\" .BR vsnprintf (),
1622 .\"O .\" and the length modifier q.
1623 .\" 4.4BSD ¤Ç¤Ï¡¢´Ø¿ô
1624 .\" .BR snprintf ()¤È
1625 .\" .BR vsnprintf ()¡¢
1626 .\" Ä¹¤µ½¤¾þ»Ò q ¤¬Æ³Æþ¤µ¤ì¤¿¡£
1627 .\"O .\" FreeBSD also has functions
1628 .\"O .\" .BR asprintf ()
1629 .\"O .\" and
1630 .\"O .\" .BR vasprintf (),
1631 .\"O .\" that allocate a buffer large enough for
1632 .\"O .\" .BR sprintf ().
1633 .\" FreeBSD ¤Ç¤Ï¡¢
1634 .\" .BR sprintf ()
1635 .\" ¤Î¤¿¤á¤Ë½½Ê¬¤Ê¥Ð¥Ã¥Õ¥¡¤ò³ÎÊݤ¹¤ë
1636 .\" .BR asprintf ()
1637 .\" ¤È
1638 .\" .BR vasprintf ()
1639 .\" ¤¬Äɲ䵤ì¤Æ¤¤¤ë¡£
1640 .\"O .\" In glibc there are functions
1641 .\"O .\" .BR dprintf ()
1642 .\"O .\" and
1643 .\"O .\" .BR vdprintf ()
1644 .\"O .\" that print to a file descriptor instead of a stream.
1645 .\" glibc ¤Ë¤Ï¡¢´Ø¿ô
1646 .\" .BR dprintf (),
1647 .\" .BR vdprintf ()
1648 .\" ¤¬¤¢¤ê¡¢¤³¤ì¤é¤Ï¥¹¥È¥ê¡¼¥à¤Ç¤Ï¤Ê¤¯¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë½ÐÎϤ¹¤ë¡£
1649 .\"O .SH BUGS
1650 .SH ¥Ð¥°
1651 .\"O Because
1652 .\"O .BR sprintf ()
1653 .\"O and
1654 .\"O .BR vsprintf ()
1655 .\"O assume an arbitrarily long string, callers must be careful not to overflow
1656 .\"O the actual space; this is often impossible to assure.
1657 .\"O Note that the length
1658 .\"O of the strings produced is locale-dependent and difficult to predict.
1659 .BR sprintf ()
1660 ¤È
1661 .BR vsprintf ()
1662 ¤Ï¾¡¼ê¤Ë½½Ê¬¤ËŤ¤Ê¸»úÎóÎΰ褬¤¢¤ë¤È²¾Äꤹ¤ë¤Î¤Ç¡¢¸Æ¤Ó½Ð¤·Â¦¤Ï
1663 ¼ÂºÝ¤ÎÎΰ褫¤é¤¢¤Õ¤ì¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
1664 ¤·¤«¤·¡¢¤³¤ì¤òÊݾڤ¹¤ë¤³¤È¤¬ÉÔ²Äǽ¤Ê¾ì¹ç¤¬Â¿¤¤¡£
1665 À¸À®¤µ¤ì¤ëʸ»úÎó¤ÎŤµ¤Ï¥í¥±¡¼¥ë°Í¸¤Ç¤¢¤ê¡¢Í½Â¬¤¬Æñ¤·¤¤¤³¤È¤ËÃí°Õ¡£
1666 .\"O Use
1667 .\"O .BR snprintf ()
1668 .\"O and
1669 .\"O .BR vsnprintf ()
1670 .\"O instead (or
1671 .\"O .BR asprintf (3)
1672 .\"O and
1673 .\"O .BR vasprintf (3)).
1674 Âå¤ï¤ê¤Ë
1675 .BR snprintf ()
1676 ¤È
1677 .BR vsnprintf ()
1678 (¤Þ¤¿¤Ï
1679 .BR asprintf (3)
1680 ¤È
1681 .BR vasprintf (3))
1682 ¤ò»È¤¦¤³¤È¡£
1683 .PP
1684 .\"O Linux libc4.[45] does not have a
1685 .\"O .BR snprintf (),
1686 .\"O but provides a libbsd that contains an
1687 .\"O .BR snprintf ()
1688 .\"O equivalent to
1689 .\"O .BR sprintf (),
1690 .\"O that is, one that ignores the
1691 .\"O .I size
1692 .\"O argument.
1693 Linux libc4.[45] ¤Ë¤Ï
1694 .BR snprintf ()
1695 ¤Ï¤Ê¤¤¤¬¡¢ libbsd ¤¬Ä󶡤µ¤ì¤Æ¤ª¤ê¡¢
1696 ¤½¤ÎÃæ¤Ë¤Ï
1697 .BR sprintf ()
1698 ¤ÈÅù²Á¤Ê (¤Ä¤Þ¤ê
1699 .I size
1700 °ú¤­¿ô¤ò̵»ë¤¹¤ë)
1701 .BR snprintf ()
1702 ¤¬¤¢¤ë¡£
1703 .\"O Thus, the use of
1704 .\"O .BR snprintf ()
1705 .\"O with early libc4 leads to serious security problems.
1706 ¤·¤¿¤¬¤Ã¤Æ¡¢½é´ü¤Î libc4 ¤Ç
1707 .BR snprintf ()
1708 ¤ò»È¤¦¤È¡¢¿¼¹ï¤Ê¥»¥­¥å¥ê¥Æ¥£ÌäÂê¤ò°ú¤­µ¯¤³¤¹¤³¤È¤¬¤¢¤ë¡£
1709 .PP
1710 .\"O Code such as
1711 .\"O .BI printf( foo );
1712 .\"O often indicates a bug, since
1713 .\"O .I foo
1714 .\"O may contain a % character.
1715 .\"O If
1716 .\"O .I foo
1717 .\"O comes from untrusted user input, it may contain \fB%n\fP, causing the
1718 .\"O .BR printf ()
1719 .\"O call to write to memory and creating a security hole.
1720 .BI printf( foo );
1721 ¤Î¤è¤¦¤Ê¥³¡¼¥É¤Ï¤·¤Ð¤·¤Ð¥Ð¥°¤ò°ú¤­µ¯¤³¤¹¡£
1722 ¤Ê¤¼¤Ê¤é
1723 .I foo
1724 ¤Ë % Ê¸»ú¤¬´Þ¤Þ¤ì¤Æ¤ë¤«¤â¤·¤ì¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
1725 .I foo
1726 ¤¬¿®Íê¤Ç¤­¤Ê¤¤¥æ¡¼¥¶¡¼ÆþÎϤ«¤éºî¤é¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
1727 ¤½¤ÎÃæ¤Ë \fB%n\fP ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ê¡¢
1728 .BR printf ()
1729 ¸Æ¤Ó½Ð¤·»þ¤Ë¥á¥â¥ê¤Ø¤Î½ñ¤­¹þ¤ß¤¬µ¯¤³¤ê¡¢
1730 ¥»¥­¥å¥ê¥Æ¥£¡¼¥Û¡¼¥ë¤òºî¤ë¤³¤È¤Ë¤Ê¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
1731 .\".PP
1732 .\".\"O Some floating-point conversions under early libc4
1733 .\".\"O caused memory leaks.
1734 .\"½é´ü¤Î libc4 ¤Ç¤Î¼Â¿ôÊÑ´¹¤Ë¤Ï¥á¥â¥ê¥ê¡¼¥¯¤ò°ú¤­µ¯¤³¤¹¤³¤È¤¬¤¢¤ë¡£
1735 .\"O .SH EXAMPLE
1736 .SH Îã
1737 .if \w'\*(Pi'=0 .ds Pi pi
1738 .\"O To print \*(Pi to five decimal places:
1739 \*(Pi ¤ò 5 ·å¤Ç½ÐÎϤ¹¤ë¡£
1740 .in +4n
1741 .nf
1742
1743 #include <math.h>
1744 #include <stdio.h>
1745 fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0));
1746 .fi
1747 .in
1748 .PP
1749 .\"O To print a date and time in the form "Sunday, July 3, 10:02",
1750 .\"O where
1751 .\"O .I weekday
1752 .\"O and
1753 .\"O .I month
1754 .\"O are pointers to strings:
1755 ÆüÉդȻþ´Ö¤ò "Sunday, July 3, 10:02" ¤Î·Á¼°¤Ç½ÐÎϤ¹¤ë¡£
1756 .RI ( weekday
1757 ¤È
1758 .I month
1759 ¤Ïʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë)
1760 .in +4n
1761 .nf
1762
1763 #include <stdio.h>
1764 fprintf(stdout, "%s, %s %d, %.2d:%.2d\en",
1765         weekday, month, day, hour, min);
1766 .fi
1767 .in
1768 .PP
1769 .\"O Many countries use the day-month-year order.
1770 .\"O Hence, an internationalized version must be able to print
1771 .\"O the arguments in an order specified by the format:
1772 Æü - ·î - Ç¯ ¤Î½ç½ø¤Çɽ¼¨¤ò¹Ô¤¦¹ñ¤â¿¤¤¡£
1773 ½¾¤Ã¤Æ¡¢¹ñºÝÈǤǤϽñ¼°¤Ç»ØÄꤵ¤ì¤¿½çÈÖ¤Ç
1774 °ú¤­¿ô¤òɽ¼¨¤Ç¤­¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
1775 .in +4n
1776 .nf
1777
1778 #include <stdio.h>
1779 fprintf(stdout, format,
1780         weekday, month, day, hour, min);
1781
1782 .fi
1783 .in
1784 .\"O where
1785 .\"O .I format
1786 .\"O depends on locale, and may permute the arguments.
1787 .\"O With the value:
1788 .I format
1789 ¤Ï¥í¥±¡¼¥ë¤Ë°Í¸¤·¤Æ¤ª¤ê¡¢°ú¤­¿ô¤Î½çÈÖ¤òÊѤ¨¤ë¤³¤È¤â¤Ç¤­¤ë¡£
1790 .I format
1791 ¤¬
1792 .in +4n
1793 .nf
1794
1795 "%1$s, %3$d. %2$s, %4$d:%5$.2d\en"
1796
1797 .fi
1798 .in
1799 .\"O one might obtain "Sonntag, 3. Juli, 10:02".
1800 ¤Ç¤¢¤ì¤Ð¡¢ "Sonntag, 3. Juli, 10:02" ¤È¤¤¤¦·ë²Ì¤Ë¤Ê¤ë¡£
1801 .PP
1802 .\"O To allocate a sufficiently large string and print into it
1803 .\"O (code correct for both glibc 2.0 and glibc 2.1):
1804 ½½Ê¬¤ËÂ礭¤Êʸ»úÎóÎΰè¤ò³ÎÊݤ·¤Æ¡¢¤½¤³¤Ë¥á¥Ã¥»¡¼¥¸¤ò³ÊǼ¤¹¤ë¤Ë¤Ï
1805 (glibc 2.0 ¤È glibc 2.1 ¤ÎξÊý¤ÇÀµ¤·¤¯Æ°ºî¤¹¤ë¥³¡¼¥É):
1806 .nf
1807
1808 #include <stdio.h>
1809 #include <stdlib.h>
1810 #include <stdarg.h>
1811 char *
1812 make_message(const char *fmt, ...)
1813 {
1814     /* Guess we need no more than 100 bytes. */
1815     int n, size = 100;
1816     char *p, *np;
1817     va_list ap;
1818
1819     if ((p = malloc(size)) == NULL)
1820         return NULL;
1821
1822     while (1) {
1823         /* Try to print in the allocated space. */
1824         va_start(ap, fmt);
1825         n = vsnprintf(p, size, fmt, ap);
1826         va_end(ap);
1827         /* If that worked, return the string. */
1828         if (n > \-1 && n < size)
1829             return p;
1830         /* Else try again with more space. */
1831         if (n > \-1)    /* glibc 2.1 */
1832             size = n+1; /* precisely what is needed */
1833         else           /* glibc 2.0 */
1834             size *= 2;  /* twice the old size */
1835         if ((np = realloc (p, size)) == NULL) {
1836             free(p);
1837             return NULL;
1838         } else {
1839             p = np;
1840         }
1841     }
1842 }
1843 .fi
1844 .\"O .SH "SEE ALSO"
1845 .SH ´ØÏ¢¹àÌÜ
1846 .BR printf (1),
1847 .BR asprintf (3),
1848 .BR dprintf (3),
1849 .BR scanf (3),
1850 .BR setlocale (3),
1851 .BR wcrtomb (3),
1852 .BR wprintf (3),
1853 .BR locale (5)