OSDN Git Service

(split) LDP: Translation snapshots for ja.po.
[linuxjm/LDP_man-pages.git] / draft / man3 / scanf.3
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\"    must display the following acknowledgement:
18 .\"     This product includes software developed by the University of
19 .\"     California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\"    may be used to endorse or promote products derived from this software
22 .\"    without specific prior written permission.
23 .\"
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" SUCH DAMAGE.
35 .\"
36 .\"     @(#)scanf.3     6.14 (Berkeley) 1/8/93
37 .\"
38 .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
39 .\" modified to resemble the GNU libio setup used in the Linux libc
40 .\" used in versions 4.x (x>4) and 5   Helmut.Geyer@iwr.uni-heidelberg.de
41 .\" Modified, aeb, 970121
42 .\" 2005-07-14, mtk, added description of %n$ form; various text
43 .\"     incorporated from the GNU C library documentation ((C) The
44 .\"     Free Software Foundation); other parts substantially rewritten.
45 .\"
46 .\" 2008-06-23, mtk
47 .\"     Add ERRORS section.
48 .\"     Document the 'a' and 'm' modifiers for dynamic string allocation.
49 .\"
50 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
51 .\"       all rights reserved.
52 .\" Translated 1998-02-17, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
53 .\" Updated 2003-02-23, Kentaro Shirakata <argrath@ub32.org>
54 .\" Updated 2005-09-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
55 .\" Updated 2008-08-11, Akihiro MOTOKI, LDP v3.05
56 .\"
57 .\"WORD:        conversion specifications       変換指定
58 .\"WORD:        type modifier                   型修飾子
59 .\"
60 .TH SCANF 3  2011-09-28 "GNU" "Linux Programmer's Manual"
61 .\"O .SH NAME
62 .SH 名前
63 .\"O scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf \- input format conversion
64 scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf \- 書式付き入力変換
65 .\"O .SH SYNOPSIS
66 .SH 書式
67 .nf
68 .B #include <stdio.h>
69
70 .BI "int scanf(const char *" format ", ...);"
71 .BI "int fscanf(FILE *" stream ", const char *" format ", ...);"
72 .BI "int sscanf(const char *" str ", const char *" format ", ...);"
73 .sp
74 .B #include <stdarg.h>
75
76 .BI "int vscanf(const char *" format ", va_list " ap );
77 .BI "int vsscanf(const char *" str ", const char *" format ", va_list " ap );
78 .BI "int vfscanf(FILE *" stream ", const char *" format ", va_list " ap );
79 .fi
80 .sp
81 .in -4n
82 .\"O Feature Test Macro Requirements for glibc (see
83 .\"O .BR feature_test_macros (7)):
84 glibc 向けの機能検査マクロの要件
85 .RB ( feature_test_macros (7)
86 参照):
87 .in
88 .ad l
89 .sp
90 .BR vscanf (),
91 .BR vsscanf (),
92 .BR vfscanf ():
93 .RS 4
94 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
95 _POSIX_C_SOURCE\ >=\ 200112L;
96 .br
97 or
98 .I "cc -std=c99"
99 .ad
100 .RE
101 .\"O .SH DESCRIPTION
102 .SH 説明
103 .\"O The
104 .\"O .BR scanf ()
105 .\"O family of functions scans input according to
106 .\"O .I format
107 .\"O as described below.
108 .\"O This format may contain
109 .\"O .IR "conversion specifications" ;
110 .\"O the results from such conversions, if any,
111 .\"O are stored in the locations pointed to by the
112 .\"O .I pointer
113 .\"O arguments that follow
114 .\"O .IR format .
115 .\"O Each
116 .\"O .I pointer
117 .\"O argument must be of a type that is appropriate for the value returned
118 .\"O by the corresponding conversion specification.
119 .BR scanf ()
120 関数グループは、以下に述べるように、
121 .I format
122 に従って入力を読み込むものである。
123 この書式には
124 .I "「変換指定」 (conversion specifications)"
125 を含めることができ、変換指定があれば、その変換の結果は
126 .I format
127 に続く
128 .I pointer
129 引き数が指す場所に格納される。
130 それぞれの
131 .I pointer
132 引き数の型は、対応する変換指定が返す値に
133 適合していなければならない。
134
135 .\"O If the number of conversion specifications in
136 .\"O .I format
137 .\"O exceeds the number of
138 .\"O .I pointer
139 .\"O arguments, the results are undefined.
140 .\"O If the number of
141 .\"O .I pointer
142 .\"O arguments exceeds the number of conversion specifications, then the excess
143 .\"O .I pointer
144 .\"O arguments are evaluated, but are otherwise ignored.
145 .I format
146 中の変換指定の個数が
147 .I pointer
148 引き数の数より多かった場合の結果は未定義である。
149 .I pointer
150 引き数の数が変換指定の個数よりも多かった場合、
151 余分な
152 .I pointer
153 引き数の評価は行われるが、それ以外は行われず無視される。
154
155 .\"O The
156 .\"O .BR scanf ()
157 .\"O function reads input from the standard input stream
158 .\"O .IR stdin ,
159 .\"O .BR fscanf ()
160 .\"O reads input from the stream pointer
161 .\"O .IR stream ,
162 .\"O and
163 .\"O .BR sscanf ()
164 .\"O reads its input from the character string pointed to by
165 .\"O .IR str .
166 .BR scanf ()
167 関数は標準入力ストリーム
168 .I stdin
169 からの入力を読み込む。
170 .BR fscanf ()
171 はストリームポインタ
172 .I stream
173 からの入力を読み込む。
174 .BR sscanf ()
175 は文字列ポインタ
176 .I str
177 で示された文字列からの入力を読み込む。
178 .PP
179 .\"O The
180 .\"O .BR vfscanf ()
181 .\"O function is analogous to
182 .\"O .BR vfprintf (3)
183 .\"O and reads input from the stream pointer
184 .\"O .I stream
185 .\"O using a variable argument list of pointers (see
186 .\"O .BR stdarg (3).
187 .BR vfscanf ()
188 関数は
189 .BR vfprintf (3)
190 と同様に、ストリームポインタ
191 .I stream
192 からの入力をポインタの可変長引き数リストを用いて読み込む
193 .RB ( stdarg (3)
194 を参照)。
195 .\"O The
196 .\"O .BR vscanf ()
197 .\"O function scans a variable argument list from the standard input and the
198 .\"O .BR vsscanf ()
199 .\"O function scans it from a string; these are analogous to the
200 .\"O .BR vprintf (3)
201 .\"O and
202 .\"O .BR vsprintf (3)
203 .\"O functions respectively.
204 .BR vscanf ()
205 関数は、可変長引き数のリストに基づき標準入力からの読み取りを行う。
206 .BR vsscanf ()
207 関数はそのリストに基づき文字列から読み取る。
208 これらの関係は
209 .BR vprintf (3)
210
211 .BR vsprintf (3)
212 関数の関係と同様である。
213 .PP
214 .\"O The
215 .\"O .I format
216 .\"O string consists of a sequence of
217 .\"O .I directives
218 .\"O which describe how to process the sequence of input characters.
219 .\"O If processing of a directive fails, no further input is read, and
220 .\"O .BR scanf ()
221 .\"O returns.
222 .\"O A "failure" can be either of the following:
223 .\"O .IR "input failure" ,
224 .\"O meaning that input characters were unavailable, or
225 .\"O .IR "matching failure" ,
226 .\"O meaning that the input was inappropriate (see below).
227 .I format
228 文字列は
229 .I "「命令」 (directive)"
230 の列で構成される。命令は入力文字の系列をどのように処理するかを指示する
231 ものである。ある命令の処理が失敗すると、入力はそれ以上読み込まれず、
232 .BR scanf ()
233 は返る。「失敗」は
234 .I "「入力の失敗」 (input failure)"
235
236 .I "「一致の失敗」 (matching failure)"
237 のいずれかである。
238 入力の失敗は入力文字が使用できなかったことを意味し、
239 一致の失敗は入力が不適切であったこと (下記参照) を意味する。
240
241 .\"O A directive is one of the following:
242 命令は以下のいずれかである:
243 .TP
244 \(bu
245 .\"O A sequence of white-space characters (space, tab, newline, etc.; see
246 .\"O .BR isspace (3)).
247 .\"O This directive matches any amount of white space,
248 .\"O including none, in the input.
249 ホワイトスペース (スペース、タブ、改行など;
250 .BR isspace (3)
251 参照) の列。
252 この命令は、入力中の任意の個数のホワイトスペースに一致する。
253 (「何もなし」にも一致する)。
254 .TP
255 \(bu
256 .\"O An ordinary character (i.e., one other than white space or \(aq%\(aq).
257 .\"O This character must exactly match the next character of input.
258 通常文字 (つまり、ホワイトスペースと \(aq%\(aq 以外の文字)。
259 この文字は入力の次の文字に正確に一致しなければならない。
260 .TP
261 \(bu
262 .\"O A conversion specification,
263 .\"O which commences with a \(aq%\(aq (percent) character.
264 .\"O A sequence of characters from the input is converted according to
265 .\"O this specification, and the result is placed in the corresponding
266 .\"O .I pointer
267 .\"O argument.
268 .\"O If the next item of input does not match the conversion specification,
269 .\"O the conversion fails\(emthis is a
270 .\"O .IR "matching failure" .
271 変換指定。変換指定は \(aq%\(aq (パーセント) 文字で始まる。
272 入力された文字の系列はこの指定にもとづいて変換され、
273 変換結果は対応する
274 .I pointer
275 引き数が指す場所に格納される。
276 入力の次の文字が変換指定と一致しない場合は、変換は失敗する
277 \(emこれが
278 .I "「一致の失敗」 (matching failure)"
279 である。
280 .PP
281 .\"O Each
282 .\"O .I conversion specification
283 .\"O in
284 .\"O .I format
285 .\"O begins with either the character \(aq%\(aq or the character sequence
286 .\"O "\fB%\fP\fIn\fP\fB$\fP"
287 .\"O (see below for the distinction) followed by:
288 .I format
289 中の各々の
290 .I "「変換指定」"
291 は文字 \(aq%\(aq か文字系列 "\fB%\fP\fIn\fP\fB$\fP"
292 (違いについては後述) で始まり、以下の要素が続く。
293 .TP
294 \(bu
295 .\"O An optional \(aq*\(aq assignment-suppression character:
296 .\"O .BR scanf ()
297 .\"O reads input as directed by the conversion specification,
298 .\"O but discards the input.
299 .\"O No corresponding
300 .\"O .I pointer
301 .\"O argument is required, and this specification is not
302 .\"O included in the count of successful assignments returned by
303 .\"O .BR scanf ().
304 代入抑制文字 \(aq*\(aq (省略可能)。
305 .BR scanf ()
306 は変換指定に指示された通り入力を読み込むが、その入力は捨てられる。
307 対応する
308 .I pointer
309 引き数は必要なく、
310 .BR scanf ()
311 が返す代入が成功した数にこの指定は含まれない。
312 .TP
313 \(bu
314 .\"O An optional \(aqa\(aq character.
315 .\"O This is used with string conversions, and relieves the caller of the
316 .\"O need to allocate a corresponding buffer to hold the input: instead,
317 .\"O .BR scanf ()
318 .\"O allocates a buffer of sufficient size,
319 .\"O and assigns the address of this buffer to the corresponding
320 .\"O .I pointer
321 .\"O argument, which should be a pointer to a
322 .\"O .I "char *"
323 .\"O variable (this variable does not need to be initialized before the call).
324 .\"O The caller should subsequently
325 .\"O .BR free (3)
326 .\"O this buffer when it is no longer required.
327 .\"O This is a GNU extension;
328 .\"O C99 employs the \(aqa\(aq character as a conversion specifier (and
329 .\"O it can also be used as such in the GNU implementation).
330 文字 \(aqa\(aq (省略可能)。これは文字列変換とともに使用され、これを使うと
331 呼び出し元が入力を保持する対応するバッファを確保する必要がなくなる。
332 代わりに
333 .BR scanf ()
334 が必要な大きさのバッファを確保し、このバッファのアドレスを
335 対応する
336 .I pointer
337 引き数に代入する。
338 .I pointer
339 引き数は
340 .I "char *"
341 型の変数へのポインタでなければならない
342 (変数自体は呼び出し前に初期化されている必要はない)。
343 呼び出し元は、不要になった時点で、このバッファを
344 .BR free (3)
345 すべきである。この機能は GNU による拡張である。
346 C99 は \(aqa\(aq 文字を変換指定として使用している
347 (こちらも GNU の実装と同じように使用することができる)。
348 .TP
349 \(bu
350 .\"O An optional decimal integer which specifies the
351 .\"O .IR "maximum field width" .
352 .\"O Reading of characters stops either when this maximum is reached or
353 .\"O when a nonmatching character is found, whichever happens first.
354 .\"O Most conversions discard initial white space characters (the exceptions
355 .\"O are noted below),
356 .\"O and these discarded characters don't count toward the maximum field width.
357 .\"O String input conversions store a terminating null byte (\(aq\\0\(aq)
358 .\"O to mark the end of the input;
359 .\"O the maximum field width does not include this terminator.
360 .I "「最大フィールド幅」"
361 を指定する 10進数 (省略可能)。
362 この最大値に達するか、一致しない文字が見つかるか、のどちらかに
363 なると、文字の読み込みを停止する。
364 ほとんどの変換では、先頭のホワイトスペース文字は捨てられ
365 (例外については後述する)、
366 捨てられたこれらの文字は最大フィールド幅の計算には含まれない。
367 文字列の入力変換では、入力の末尾を示す終端の NULL バイト (\(aq\\0\(aq)
368 も格納されるが、最大フィールド幅にはこの終端バイトは含まれない。
369 .TP
370 \(bu
371 .\"O An optional
372 .\"O .IR "type modifier character" .
373 .\"O For example, the
374 .\"O .B l
375 .\"O type modifier is used with integer conversions such as
376 .\"O .B %d
377 .\"O to specify that the corresponding
378 .\"O .I pointer
379 .\"O argument refers to a
380 .\"O .I "long int"
381 .\"O rather than a pointer to an
382 .\"O .IR int .
383 .I "「型修飾子」 (type modifier characters)"
384 (省略可能)。
385 例えば、型修飾子
386 .B l
387
388 .B %d
389 などの整数変換と一緒に使うと、対応する
390 .I pointer
391 引き数が
392 .I int
393 ではなく
394 .I "long int"
395 を参照していることを指定できる。
396 .TP
397 \(bu
398 .\"O A
399 .\"O .I "conversion specifier"
400 .\"O that specifies the type of input conversion to be performed.
401 .I "「変換指定」"
402 : 実行すべき入力変換の種類を指定する。
403 .PP
404 .\"O The conversion specifications in
405 .\"O .I format
406 .\"O are of two forms, either beginning with \(aq%\(aq or beginning with
407 .\"O "\fB%\fP\fIn\fP\fB$\fP".
408 .\"O The two forms should not be mixed in the same
409 .\"O .I format
410 .\"O string, except that a string containing
411 .\"O "\fB%\fP\fIn\fP\fB$\fP"
412 .\"O specifications can include
413 .\"O .B %%
414 .\"O and
415 .\"O .BR %* .
416 .I format
417 中の変換指定は、\(aq%\(aq で始まるか、
418 "\fB%\fP\fIn\fP\fB$\fP" で始まるかの、いずれかの形式である。
419 これら 2つの形式を同じ
420 .I format
421 文字列に混ぜることはできない。但し、"\fB%\fP\fIn\fP\fB$\fP" を
422 含む文字列に
423 .B %%
424
425 .B %*
426 を含めることはできる。
427 .\"O If
428 .\"O .I format
429 .\"O contains \(aq%\(aq
430 .\"O specifications then these correspond in order with successive
431 .\"O .I pointer
432 .\"O arguments.
433 .I format
434 に \(aq%\(aq 指定が含まれている場合、各々の \(aq%\(aq 指定と
435 後続の
436 .I pointer
437 引き数はその順番通りに対応する。
438 .\"O In the
439 .\"O "\fB%\fP\fIn\fP\fB$\fP"
440 .\"O form (which is specified in POSIX.1-2001, but not C99),
441 .\"O .I n
442 .\"O is a decimal integer that specifies that the converted input should
443 .\"O be placed in the location referred to by the
444 .\"O .IR n -th
445 .\"O .I pointer
446 .\"O argument following
447 .\"O .IR format .
448 "\fB%\fP\fIn\fP\fB$\fP" 形式
449 (POSIX.1-2001 では規定されているが、C99 にはない)
450 では、
451 .I n
452 は 10進数であり、変換後の入力を
453 .I format
454 の後ろの
455 .I n
456 番目の
457 .I pointer
458 引き数が参照する場所に格納することを指定する。
459 .\"O .SS Conversions
460 .SS 変換
461 .\"O The following
462 .\"O .I "type modifier characters"
463 .\"O can appear in a conversion specification:
464 変換指定には、以下の
465 .I "「型修飾子」"
466 を入れることができる。
467 .TP
468 .B h
469 .\"O Indicates that the conversion will be one of
470 .\"O \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP, or \fBn\fP
471 .\"O and the next pointer is a pointer to a
472 .\"O .I short int
473 .\"O or
474 .\"O .I unsigned short int
475 .\"O (rather than
476 .\"O .IR int ).
477 変換が
478 \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP, \fBn\fP
479 のいずれかであり、次のポインタが
480 .RI ( int
481 ではなく)
482 .I short int
483
484 .I unsigned short int
485 へのポインタであることを示す。
486 .TP
487 .B hh
488 .\"O As for
489 .\"O .BR h ,
490 .\"O but the next pointer is a pointer to a
491 .\"O .I signed char
492 .\"O or
493 .\"O .IR "unsigned char" .
494 .B h
495 と同じだが、次のポインタが
496 .I signed char
497
498 .I unsigned char
499 へのポインタであることを示す。
500 .TP
501 .B j
502 .\"O As for
503 .\"O .BR h ,
504 .\"O but the next pointer is a pointer to an
505 .\"O .I intmax_t
506 .\"O or a
507 .\"O .IR uintmax_t .
508 .\"O This modifier was introduced in C99.
509 .B h
510 と同じだが、次のポインタが
511 .I intmax_t
512
513 .I uintmax_t
514 へのポインタであることを示す。
515 この修飾子は C99 で導入された。
516 .TP
517 .B l
518 .\"O Indicates either that the conversion will be one of
519 .\"O \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP, or \fBn\fP
520 .\"O and the next pointer is a pointer to a
521 .\"O .I long int
522 .\"O or
523 .\"O .I unsigned long int
524 .\"O (rather than
525 .\"O .IR int ),
526 .\"O or that the conversion will be one of
527 .\"O \fBe\fP, \fBf\fP, or \fBg\fP
528 .\"O and the next pointer is a pointer to
529 .\"O .I double
530 .\"O (rather than
531 .\"O .IR float ).
532 変換が
533 \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP, \fBn\fP
534
535 .B n
536 のいずれかであり次のポインタが
537 .RI ( int
538 ではなく)
539 .I long int
540
541 .I unsigned long int
542 へのポインタであること、または、変換が
543 \fBe\fP, \fBf\fP, \fBg\fP
544 のうちのひとつであり次のポインタが
545 .RI ( float
546 ではなく)
547 .I double
548 へのポインタであることのいずれかであることを示す。
549 .\"O Specifying two
550 .\"O .B l
551 .\"O characters is equivalent to
552 .\"O .BR L .
553 .\"O If used with
554 .\"O .B %c
555 .\"O or
556 .\"O .B %s
557 .\"O the corresponding parameter is considered
558 .\"O as a pointer to a wide character or wide-character string respectively.
559 .\"O .\" This use of l was introduced in Amendment 1 to ISO C90.
560 .B l
561 文字を二つ指定すると、
562 .B L
563 と同じ意味となる。
564 .B %c
565
566 .B %s
567 とともに使用すると、
568 パラメータはそれぞれワイド文字やワイド文字列へのポインタであると
569 みなされる。
570 .\" l のこの使用法は ISO C90 の Amendment 1 で導入された。
571 .TP
572 .B L
573 .\"O Indicates that the conversion will be either
574 .\"O \fBe\fP, \fBf\fP, or \fBg\fP
575 .\"O and the next pointer is a pointer to
576 .\"O .I "long double"
577 .\"O or the conversion will be
578 .\"O \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, or \fBx\fP
579 .\"O and the next pointer is a pointer to
580 .\"O .IR "long long" .
581 \fBe\fP, \fBf\fP, \fBg\fP
582 変換で、次のポインタが
583 .I "long double"
584 へのポインタであることを示す。もしくは、
585 \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP
586 変換で、次のポインタが
587 .I "long long"
588 へのポインタであることのいずれかであることを示す。
589 .\"O .\" MTK, Jul 05: The following is no longer true for modern
590 .\"O .\" ANSI C (i.e., C99):
591 .\"O .\" (Note that long long is not an
592 .\"O .\" ANSI C
593 .\"O .\" type. Any program using this will not be portable to all
594 .\"O .\" architectures).
595 .\" MTK, Jul 05: 以下の内容は新しい ANSI C (つまり C99) では
596 .\" もはや正しくない。
597 .\" (long long は
598 .\" .I ANSI C
599 .\" で規定された型ではないことに注意しよう。
600 .\" これを用いたプログラムは全てのアーキテクチャに対して
601 .\" 移植可能ではない。)
602 .TP
603 .B q
604 .\"O equivalent to
605 .\"O .BR L .
606 .\"O This specifier does not exist in ANSI C.
607 .B L
608 と同一である。
609 この修飾子は ANSI C には存在しない。
610 .TP
611 .B t
612 .\"O As for
613 .\"O .BR h ,
614 .\"O but the next pointer is a pointer to a
615 .\"O .IR ptrdiff_t .
616 .\"O This modifier was introduced in C99.
617 .B h
618 と同様だが、次のポインタが
619 .I ptrdiff_t
620 へのポインタであることを示す。
621 この修飾子は C99 で導入された。
622 .TP
623 .B z
624 .\"O As for
625 .\"O .BR h ,
626 .\"O but the next pointer is a pointer to a
627 .\"O .IR size_t .
628 .\"O This modifier was introduced in C99.
629 .B h
630 と同様だが、次のポインタが
631 .I size_t
632 へのポインタであることを示す。
633 この修飾子は C99 で導入された。
634 .PP
635 .\"O The following
636 .\"O .I "conversion specifiers"
637 .\"O are available:
638 以下の
639 .I 「変換指定子」
640 が利用可能である。
641 .TP
642 .B %
643 .\"O Matches a literal \(aq%\(aq.
644 .\"O That is,
645 .\"O .B %\&%
646 .\"O in the format string matches a
647 .\"O single input \(aq%\(aq character.
648 .\"O No conversion is done (but initial white space characters are discarded),
649 .\"O and assignment does not occur.
650 文字 \(aq%\(aq に対応する。
651 書式文字列の中の
652 .B %\&%
653 は単一の文字 \(aq%\(aq に対応する。
654 変換は行われず (但し、先頭のホワイトスペース文字は捨てられる)、
655 変数への代入は生じない。
656 .TP
657 .B d
658 .\"O Matches an optionally signed decimal integer;
659 .\"O the next pointer must be a pointer to
660 .\"O .IR int .
661 符号つきの 10進の整数に対応する。
662 次のポインタは
663 .I int
664 へのポインタでなければならない。
665 .TP
666 .B D
667 .\"O Equivalent to
668 .\"O .IR ld ;
669 .\"O this exists only for backward compatibility.
670 .\"O (Note: thus only in libc4.
671 .\"O In libc5 and glibc the
672 .\"O .B %D
673 .\"O is silently ignored, causing old programs to fail mysteriously.)
674 .I ld
675 と同一である。これは以前の仕様との互換性だけのためにある。
676 (注意: これは libc4 の場合だけである。 libc5 や glibc では
677 .B %D
678 は暗黙のうちに無視され、古いプログラムにおいて謎に満ちた失敗の原因となる。)
679 .TP
680 .B i
681 .\"O Matches an optionally signed integer; the next pointer must be a pointer to
682 .\"O .IR int .
683 .\"O The integer is read in base 16 if it begins with
684 .\"O .I 0x
685 .\"O or
686 .\"O .IR 0X ,
687 .\"O in base 8 if it begins with
688 .\"O .IR 0 ,
689 .\"O and in base 10 otherwise.
690 .\"O Only characters that correspond to the base are used.
691 符号つき整数に対応する。
692 次のポインタは
693 .I int
694 へのポインタでなければならない。
695 この整数は
696 .I 0x
697 または
698 .I 0X
699 で開始する場合には 16 進数、
700 .I 0
701 で開始する場合には 8 進数、その他の場合には 10進数として読み込まれる。
702 この変換で使用される文字は、これらの基数に対応しているものだけである。
703 .TP
704 .B o
705 .\"O Matches an unsigned octal integer; the next pointer must be a pointer to
706 .\"O .IR "unsigned int" .
707 符号なしの 8 進の整数に対応する。
708 次のポインタは
709 .I "unsigned int"
710 でなければならない。
711 .TP
712 .B u
713 .\"O Matches an unsigned decimal integer; the next pointer must be a
714 .\"O pointer to
715 .\"O .IR "unsigned int" .
716 符号なしの 10進の整数に対応する。
717 次のポインタは
718 .I "unsigned int"
719 へのポインタでなければならない。
720 .TP
721 .B x
722 .\"O Matches an unsigned hexadecimal integer; the next pointer must
723 .\"O be a pointer to
724 .\"O .IR "unsigned int" .
725 符号なしの 16 進の整数に対応する。
726 次のポインタは
727 .I "unsigned int"
728 へのポインタでなければならない。
729 .TP
730 .B X
731 .\"O Equivalent to
732 .\"O .BR x .
733 .B x
734 と同一である。
735 .TP
736 .B f
737 .\"O Matches an optionally signed floating-point number; the next pointer must
738 .\"O be a pointer to
739 .\"O .IR float .
740 符号つき浮動小数点実数に対応する。
741 次のポインタは
742 .I float
743 へのポインタでなければならない。
744 .TP
745 .B e
746 .\"O Equivalent to
747 .\"O .BR f .
748 .B f
749 と同一である。
750 .TP
751 .B g
752 .\"O Equivalent to
753 .\"O .BR f .
754 .B f
755 と同一である。
756 .TP
757 .B E
758 .\"O Equivalent to
759 .\"O .BR f .
760 .B f
761 と同一である。
762 .TP
763 .B a
764 .\"O (C99) Equivalent to
765 .\"O .BR f .
766 (C99)
767 .B f
768 と同一である。
769 .TP
770 .B s
771 .\"O Matches a sequence of non-white-space characters;
772 .\"O the next pointer must be a pointer to character array that is
773 .\"O long enough to hold the input sequence and
774 .\"O the terminating null byte (\(aq\\0\(aq), which is added automatically.
775 .\"O The input string stops at white space or at the maximum field
776 .\"O width, whichever occurs first.
777 ホワイトスペースではない文字で構成された文字列に対応する。
778 次のポインタは文字の配列へのポインタでなければならず、
779 その文字配列は、入力された文字列と (自動的に追加される) 終端の NULL
780 バイト (\(aq\\0\(aq) を格納するのに十分な大きさでなければならない。
781 文字列の入力は、ホワイトスペースが入力されるか、最大フィールド幅に
782 達するか、のどちらかが起こると停止される。
783 .TP
784 .B c
785 .\"O Matches a sequence of characters whose length is specified by the
786 .\"O .I maximum field width
787 .\"O (default 1); the next pointer must be a pointer to
788 .\"O .IR char ,
789 .\"O and there must be enough room for all the characters (no terminating
790 .\"O null byte
791 .\"O is added).
792 .\"O The usual skip of leading white space is suppressed.
793 .\"O To skip white space first, use an explicit space in the format.
794 .I "「最大フィールド幅」"
795 (デフォルトは 1) で指定された幅の文字の列に対応する。
796 次のポインタは
797 .I char
798 へのポインタで、すべての文字を格納するのに十分な領域が
799 なければならない (終端の NULL バイトは追加されない)。
800 通常行われる先頭のホワイトスペースの読み飛ばしは行われない。
801 先頭のホワイトスペースを読み飛ばすためには、
802 フォーマット文の中で明示的にスペースを使用すれば良い。
803 .TP
804 .B \&[
805 .\"O Matches a nonempty sequence of characters from the specified set of
806 .\"O accepted characters; the next pointer must be a pointer to
807 .\"O .IR char ,
808 .\"O and there must be enough room for all the characters in the string, plus a
809 .\"O terminating null byte.
810 .\"O The usual skip of leading white space is suppressed.
811 格納された文字列のうちから取り出された、
812 指定された文字の集合で構成される空ではない文字の列に対応する。
813 次のポインタは
814 .I char
815 へのポインタでなければならず、
816 そこには文字列中のすべての文字と終端の NULL バイト
817 を格納するための十分な領域がなければならない。
818 通常行われる先頭のホワイトスペースの読み飛ばしは行われない。
819 .\"O The string is to be made up of characters in (or not in) a particular set;
820 .\"O the set is defined by the characters between the open bracket
821 .\"O .B [
822 .\"O character and a close bracket
823 .\"O .B ]
824 .\"O character.
825 .\"O The set
826 .\"O .I excludes
827 .\"O those characters if the first character after the open bracket is a
828 .\"O circumflex
829 .\"O .RB ( ^ ).
830 この文字列は特別な集合の中の文字で構成されている。
831 この集合は
832 開き括弧
833 .B [
834 と閉じ括弧
835 .B ]
836 の間の文字で定義される。
837 開き括弧のあとの最初の文字が曲アクセント記号
838 .RB ( ^ )
839 の場合、集合はこれらの文字を含まないものとなる。
840 .\"O To include a close bracket in the set, make it the first character after
841 .\"O the open bracket or the circumflex; any other position will end the set.
842 .\"O The hyphen character
843 .\"O .B \-
844 .\"O is also special; when placed between two other characters, it adds all
845 .\"O intervening characters to the set.
846 .\"O To include a hyphen, make it the last
847 .\"O character before the final close bracket.
848 閉じ括弧を集合に含ませるためには、この文字を開き括弧または
849 曲アクセント記号のあとの最初の文字にすればよい。
850 つまり、他の位置に閉じ括弧を置くと文字の集合が終る。
851 ハイフン
852 .B \-
853 もまた特殊文字である。
854 二つの異なる文字の間に置かれた時、この文字は、
855 その間にある全ての文字を集合に加える。
856 ハイフン自体を含ませるためには、
857 括弧が閉じる前の最後の一文字をハイフンにすればよい。
858 .\"O For instance,
859 .\"O .B [^]0\-9\-]
860 .\"O means
861 .\"O the set "everything except close bracket, zero through nine, and hyphen".
862 .\"O The string ends with the appearance of a character not in the (or, with a
863 .\"O circumflex, in) set or when the field width runs out.
864 例えば、
865 .B [^]0\-9\-]
866 は「閉じ括弧、0 〜 9、ハイフンの 3 種類を除く全ての文字」の集合を意味する。
867 この文字列は
868 集合に含まれていない (曲アクセントの場合には含まれる) 文字の
869 出現または確保された領域が使い切られた時に終了する。
870 .TP
871 .B p
872 .\"O Matches a pointer value (as printed by
873 .\"O .B %p
874 .\"O in
875 .\"O .BR printf (3);
876 .\"O the next pointer must be a pointer to a pointer to
877 .\"O .IR void .
878 .RB ( printf (3)
879
880 .B %p
881 で印字されるような) ポインタ値に対応する。
882 次のポインタは
883 .I void
884 へのポインタへのポインタでなければならない。
885 .TP
886 .B n
887 .\"O Nothing is expected; instead, the number of characters consumed thus far
888 .\"O from the input is stored through the next pointer, which must be a pointer
889 .\"O to
890 .\"O .IR int .
891 どんな入力も必要としない。
892 そのかわりに、
893 入力からここまで消費された文字数が次のポインタで指定された場所に
894 格納される。
895 このポインタは
896 .I int
897 へのポインタでなければならない。
898 .\"O This is
899 .\"O .I not
900 .\"O a conversion, although it can be suppressed with the
901 .\"O .B *
902 .\"O assignment-suppression character.
903 変換を抑制するのであれば
904 .B *
905 代入抑制文字を使って抑制することができるのだが、
906 この変換指定子は変換では「ない」。
907 .\"O The C standard says: "Execution of a
908 .\"O .B %n
909 .\"O directive does not increment
910 .\"O the assignment count returned at the completion of execution"
911 .\"O but the Corrigendum seems to contradict this.
912 .\"O Probably it is wise
913 .\"O not to make any assumptions on the effect of
914 .\"O .B %n
915 .\"O conversions on the return value.
916 C 言語の標準規格では「実行の完了時に返される代入の回数は
917 .B %n
918 命令の実行では増加しない」となっているが、
919 正誤表の内容はこれと矛盾するようである。おそらく、
920 .B %n
921 変換が返り値に与える影響についてはどのような仮定もしないのが
922 賢明であろう。
923 .\"O .SH "RETURN VALUE"
924 .SH 返り値
925 .\"O These functions return the number of input items
926 .\"O successfully matched and assigned,
927 .\"O which can be fewer than provided for,
928 .\"O or even zero in the event of an early matching failure.
929 これらの関数は、一致と代入が成功した入力要素の個数を返す。
930 返される値は渡された変換の個数よりも少ないこともあり、
931 最初に一致の失敗があった場合には 0 になることもある。
932
933 .\"O The value
934 .\"O .B EOF
935 .\"O is returned if the end of input is reached before either the first
936 .\"O successful conversion or a matching failure occurs.
937 .\"O .B EOF
938 .\"O is also returned if a read error occurs,
939 .\"O in which case the error indicator for the stream (see
940 .\"O .BR ferror (3))
941 .\"O is set, and
942 .\"O .I errno
943 .\"O is set indicate the error.
944 最初の変換が成功する前に入力の最後に達して、一致の失敗が起こった場合には、
945 .B EOF
946 が返される。また、
947 読み込みエラーが発生した場合にも
948 .B EOF
949 が返される。読み込みエラーの場合には、そのストリームの
950 エラー指示子がセットされ
951 .RB ( ferror (3)
952 参照)、
953 .I errno
954 にエラーを示す値がセットされる。
955 .\"O .SH ERRORS
956 .SH エラー
957 .TP
958 .B EAGAIN
959 .\"O The file descriptor underlying
960 .\"O .I stream
961 .\"O is marked nonblocking, and the read operation would block.
962 .I stream
963 に対応するファイルディスクリプタが nonblocking となっており、
964 読み込み操作は停止 (block) することになる。
965 .TP
966 .B EBADF
967 .\"O The file descriptor underlying
968 .\"O .I stream
969 .\"O is invalid, or not open for reading.
970 .I stream
971 に対応するファイルディスクリプタが無効であるが、
972 読み込み用にオープンされていない。
973 .TP
974 .B EILSEQ
975 .\"O Input byte sequence does not form a valid character.
976 入力されたバイト列が有効な文字を構成していない。
977 .TP
978 .B EINTR
979 .\"O The read operation was interrupted by a signal; see
980 .\"O .BR signal (7).
981 読み込み操作がシグナルにより割り込まれた。
982 .BR signal (7)
983 参照。
984 .TP
985 .B EINVAL
986 .\"O Not enough arguments; or
987 .\"O .I format
988 .\"O is NULL.
989 引き数が十分でない。または
990 .I format
991 が NULL である。
992 .TP
993 .B ENOMEM
994 .\"O Out of memory.
995 メモリ不足。
996 .TP
997 .B ERANGE
998 .\"O The result of an integer conversion would exceed the size
999 .\"O that can be stored in the corresponding integer type.
1000 整数変換の結果が、対応する整数型に格納できるサイズを越えてしまう。
1001 .\"O .SH "CONFORMING TO"
1002 .SH 準拠
1003 .\"O The functions
1004 .\"O .BR fscanf (),
1005 .\"O .BR scanf (),
1006 .\"O and
1007 .\"O .BR sscanf ()
1008 .\"O conform to C89 and C99 and POSIX.1-2001.
1009 .\"O These standards do not specify the
1010 .\"O .B ERANGE
1011 .\"O error.
1012 .BR fscanf (),
1013 .BR scanf (),
1014 .BR sscanf ()
1015 関数は C89, C99, POSIX.1-2001 に準拠している。
1016 これらの標準では、エラー
1017 .B ERANGE
1018 は規定されていない。
1019 .PP
1020 .\"O The
1021 .\"O .B q
1022 .\"O specifier is the 4.4BSD notation for
1023 .\"O .IR "long long" ,
1024 .B q
1025 指定子は
1026 .I "long long"
1027 の 4.4BSD での記述方法である。
1028 .\"O while
1029 .\"O .B ll
1030 .\"O or the usage of
1031 .\"O .B L
1032 .\"O in integer conversions is the GNU notation.
1033 一方、整数変換での
1034 .B ll
1035 または
1036 .B L
1037 の使用は GNU での拡張である。
1038 .PP
1039 .\"O The Linux version of these functions is based on the
1040 .\"O .I GNU
1041 .\"O .I libio
1042 .\"O library.
1043 .\"O Take a look at the
1044 .\"O .I info
1045 .\"O documentation of
1046 .\"O .I GNU
1047 .\"O .I libc (glibc-1.08)
1048 .\"O for a more concise description.
1049 これらの関数の Linux 版は
1050 .I GNU
1051 .I libio
1052 ライブラリーを元にしている。
1053 より簡潔な説明には
1054 .I GNU
1055 .I libc (glibc-1.08)
1056
1057 .I info
1058 文書に目を通すこと。
1059 .\"O .SH NOTES
1060 .SH 注意
1061 .\"O The GNU C library supports a nonstandard extension that causes
1062 .\"O the library to dynamically allocate a string of sufficient size
1063 .\"O for input strings for the
1064 .\"O .B %s
1065 .\"O and
1066 .\"O \fB%a[\fP\fIrange\fP\fB]\fP
1067 .\"O conversion specifiers.
1068 GNU C ライブラリ (glibc) では非標準のオプションをサポートしており、
1069 このオプションを使うと変換指定子
1070 .B %s
1071
1072 \fB%a[\fP\fIrange\fP\fB]\fP
1073 への入力文字列に対して十分な大きさの文字列をライブラリが動的に確保する
1074 ようになる。
1075 .\"O .\" This feature seems to be present at least as far back as glibc 2.0.
1076 .\" この機能は少なくとも glibc 2.0 時点から存在しているようだ。
1077 .\"O To make use of this feature, specify
1078 .\"O .B a
1079 .\"O as a length modifier (thus
1080 .\"O .B %as
1081 .\"O or
1082 .\"O \fB%a[\fP\fIrange\fP\fB]\fP).
1083 .\"O The caller must
1084 .\"O .BR free (3)
1085 .\"O the returned string, as in the following example:
1086 この機能を使用するには、長さ修飾子として
1087 .B a
1088 を指定する (したがって、全体としては
1089 .B %as
1090
1091 \fB%a[\fP\fIrange\fP\fB]\fP となる)。
1092 以下の例にあるように、呼び出し側は返された文字列を
1093 .BR free (3)
1094 しなければならない。
1095 .in +4n
1096 .nf
1097
1098 char *p;
1099 int n;
1100
1101 errno = 0;
1102 n = scanf("%a[a-z]", &p);
1103 if (n == 1) {
1104     printf("read: %s\\n", p);
1105     free(p);
1106 } else if (errno != 0) {
1107     perror("scanf");
1108 } else {
1109     fprintf(stderr, "No matching characters\\n"):
1110 }
1111 .fi
1112 .in
1113 .PP
1114 .\"O As shown in the above example, it is only necessary to call
1115 .\"O .BR free (3)
1116 .\"O if the
1117 .\"O .BR scanf ()
1118 .\"O call successfully read a string.
1119 上記の例にあるように、
1120 .BR scanf ()
1121 が文字列の読み込みに成功した場合にだけ、
1122 .BR free (3)
1123 を呼び出す必要がある。
1124 .PP
1125 .\"O The
1126 .\"O .B a
1127 .\"O modifier is not available if the program is compiled with
1128 .\"O .I "gcc -std=c99"
1129 .\"O or
1130 .\"O .IR "gcc -D_ISOC99_SOURCE"
1131 .\"O (unless
1132 .\"O .B _GNU_SOURCE
1133 .\"O is also specified), in which case the
1134 .\"O .B a
1135 .\"O is interpreted as a specifier for floating-point numbers (see above).
1136 .I "gcc -std=c99"
1137
1138 .I "gcc -D_ISOC99_SOURCE"
1139 でコンパイルしたプログラムでは
1140 .RB ( _GNU_SOURCE
1141 も同時に指定していない場合)、
1142 .B a
1143 修飾子は利用できない。
1144 上記の場合、
1145 .B a
1146 は (上述の通り) 浮動小数点数を示す変換指定子と解釈される。
1147
1148 .\"O Since version 2.7, glibc also provides the
1149 .\"O .B m
1150 .\"O modifier for the same purpose as the
1151 .\"O .BR a
1152 .\"O modifier.
1153 .\"O The
1154 .\"O .B m
1155 .\"O modifier has the following advantages:
1156 バージョン 2.7 以降では、glibc は
1157 .B a
1158 修飾子と同じ目的で
1159 .B m
1160 修飾子も提供している。
1161 .B m
1162 修飾子は以下の利点がある。
1163 .IP * 2
1164 .\"O It may also be applied to
1165 .\"O .B %c
1166 .\"O conversion specifiers (e.g.,
1167 .\"O .BR %3mc ).
1168 .B %c
1169 変換指定子にも適用できる (例えば
1170 .BR %3mc )。
1171 .IP *
1172 .\"O It avoids ambiguity with respect to the
1173 .\"O .B %a
1174 .\"O floating-point conversion specifier (and is unaffected by
1175 .\"O .IR "gcc -std=c99"
1176 .\"O etc.)
1177 浮動小数点変換指定子としての
1178 .B %a
1179 との紛らわしさが避けられる (また
1180 .I "gcc -std=c99"
1181 などの影響も避けられる)。
1182 .IP *
1183 .\"O It is specified in the upcoming revision of the POSIX.1 standard.
1184 POSIX.1 標準の次の改訂版で規定される。
1185 .\"O .SH BUGS
1186 .SH バグ
1187 .\"O All functions are fully C89 conformant, but provide the
1188 .\"O additional specifiers
1189 .\"O .B q
1190 .\"O and
1191 .\"O .B a
1192 .\"O as well as an additional behavior of the
1193 .\"O .B L
1194 .\"O and
1195 .\"O .B l
1196 .\"O specifiers.
1197 .\"O The latter may be considered to be a bug, as it changes the
1198 .\"O behavior of specifiers defined in C89.
1199 全ての関数は、完全に C89 に準拠している。しかし
1200 追加で
1201 .B q
1202
1203 .B a
1204 指定子が提供されており、同様に
1205 .B L
1206
1207 .B l
1208 指定子の付加的な振る舞いもある。後者は、
1209 C89 で定義された指定子の振る舞いを変更するものなので、
1210 バグとみなされるかもしれない。
1211 .PP
1212 .\"O Some combinations of the type modifiers and conversion
1213 .\"O specifiers defined by ANSI C do not make sense
1214 .\"O (e.g.
1215 .\"O .BR "%Ld" ).
1216 ANSI C で定義された型修飾子と変換指定子の組み合わせの中には
1217 意味をなさないものがある
1218 (例えば、
1219 .BR "%Ld" )。
1220 .\"O While they may have a well-defined behavior on Linux, this need not
1221 .\"O to be so on other architectures.
1222 .\"O Therefore it usually is better to use
1223 .\"O modifiers that are not defined by ANSI C at all, that is, use
1224 .\"O .B q
1225 .\"O instead of
1226 .\"O .B L
1227 .\"O in combination with
1228 .\"O \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, and \fBX\fP
1229 .\"O conversions or
1230 .\"O .BR ll .
1231 これらが指定された場合、
1232 Linux 上でははっきりと定義された振る舞いをするかもしれないが、
1233 他のアーキテクチャでも同様になっているとは限らない。
1234 それゆえに、ほとんどの場合、
1235 ANSI C で定義されていない修飾子を使用した方が良い。
1236 すなわち、
1237 \fBd\fP, \fBi\fP, \fBo\fP, \fBu\fP, \fBx\fP, \fBX\fP
1238 変換や
1239 .B ll
1240 と組み合わせる場合には、
1241 .B L
1242 の代わりに
1243 .B q
1244 を使用した方が良い。
1245 .PP
1246 .\"O The usage of
1247 .\"O .B q
1248 .\"O is not the same as on 4.4BSD,
1249 .\"O as it may be used in float conversions equivalently to
1250 .\"O .BR L .
1251 .B q
1252 の使用方法は 4.4BSD と同じではない。
1253 4.4BSD では
1254 .B q
1255
1256 .B L
1257 と同等に浮動小数の変換に使用される。
1258 .\"O .SH "SEE ALSO"
1259 .SH 関連項目
1260 .BR getc (3),
1261 .BR printf (3)
1262 .BR setlocale (3),
1263 .BR strtod (3),
1264 .BR strtol (3),
1265 .BR strtoul (3),