.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" License. .\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu) .\" .\" Japanese Version Copyright (c) 1997 IMAMURA Nobutaka .\" all rights reserved. .\" Translated 1997-02-14, IMAMURA Nobutaka .\" Updated 1999-08-29, Kentaro Shirakata .\" Updated 2001-11-02, Kentaro Shirakata .\" Updated 2005-09-06, Akihiro MOTOKI .\" .TH GETS 3 2008-08-06 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O fgetc, fgets, getc, getchar, gets, ungetc \- input of characters and strings fgetc, fgets, getc, getchar, gets, ungetc \- 文字と文字列の入力 .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int fgetc(FILE *" stream ); .BI "char *fgets(char *" "s" ", int " "size" ", FILE *" "stream" ); .BI "int getc(FILE *" stream ); .B "int getchar(void);" .BI "char *gets(char *" "s" ); .BI "int ungetc(int " c ", FILE *" stream ); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O .BR fgetc () .\"O reads the next character from .\"O .I stream .\"O and returns it as an .\"O .I unsigned char .\"O cast to an .\"O .IR int , .\"O or .\"O .B EOF .\"O on end of file or error. .BR fgetc () は、 .I stream から次の文字を .I unsigned char として読み、 .I int にキャストして返す。ファイルの終わりやエラーとなった場合は .B EOF を返す。 .PP .\"O .BR getc () .\"O is equivalent to .\"O .BR fgetc () .\"O except that it may be implemented as a macro which evaluates .\"O .I stream .\"O more than once. .BR getc () は .BR fgetc () と同様だが、 .I stream を複数回評価するマクロとして実装されているかもしれない。 .PP .\"O .BR getchar () .\"O is equivalent to .\"O .BI "getc(" stdin ) \fR. .BR getchar () は .BI "getc(" stdin ) \fR と同じである。 .PP .\"O .BR gets () .\"O reads a line from .\"O .I stdin .\"O into the buffer pointed to by .\"O .I s .\"O until either a terminating newline or .\"O .BR EOF , .\"O which it replaces with .\"O .BR \(aq\e0\(aq . .BR gets () は、改行文字か .B EOF までの 1行を .I stdin から読み込み .I s が指すバッファに格納する (末尾の改行文字や .B EOF は .B \(aq\e0\(aq に置き換えられる)。 .\"O No check for buffer overrun is performed (see BUGS below). バッファ・オーバーランのチェックは行われない (下記の「バグ」を参照)。 .PP .\"O .BR fgets () .\"O reads in at most one less than .\"O .I size .\"O characters from .\"O .I stream .\"O and stores them into the buffer pointed to by .\"O .IR s . .\"O Reading stops after an .\"O .B EOF .\"O or a newline. .\"O If a newline is read, it is stored into the buffer. .\"O A .\"O .B \(aq\e0\(aq .\"O is stored after the last character in the buffer. .BR fgets () は .I stream から最大で .IR size " - 1" 個の文字を読み込み、 .I s が指すバッファに格納する。読み込みは .B EOF または改行文字を読み込んだ後で停止する。 読み込まれた改行文字はバッファに格納される。 .B \(aq\e0\(aq 文字が一つバッファの中の最後の文字の後に書き込まれる。 .PP .\"O .BR ungetc () .\"O pushes .\"O .I c .\"O back to .\"O .IR stream , .\"O cast to .\"O .IR "unsigned char" , .\"O where it is available for subsequent read operations. .\"O Pushed-back characters .\"O will be returned in reverse order; only one pushback is guaranteed. .BR ungetc () は、後の read 操作で読めるように、 .I c を .I "unsigned char" にキャストして .I stream に書き戻す。 書き戻された文字は逆順に戻される; 書き戻しとして保証されているのは、一文字だけである。 .PP .\"O Calls to the functions described here can be mixed with each other and with .\"O calls to other input functions from the .\"O .I stdio .\"O library for the same input stream. ここで述べた関数や .I stdio ライブラリの入力関数を同じ入力ストリームに対して互いに混ぜて使うことができる。 .PP .\"O For nonlocking counterparts, see .\"O .BR unlocked_stdio (3). これらの処理をロックせずに行いたいときは、 .BR unlocked_stdio (3) を参照のこと。 .\"O .SH "RETURN VALUES" .SH 返り値 .\"O .BR fgetc (), .\"O .BR getc () .\"O and .\"O .BR getchar () .\"O return the character read as an .\"O .I unsigned char .\"O cast to an .\"O .I int .\"O or .\"O .B EOF .\"O on end of file or error. .BR fgetc (), .BR getc (), .BR getchar () は、文字を .I unsigned char として読んで .I int にキャストして返す。ファイルの終わりやエラーの場合は .B EOF を返す。 .PP .\"O .BR gets () .\"O and .\"O .BR fgets () .\"O return .\"O .I s .\"O on success, and NULL .\"O on error or when end of file occurs while no characters have been read. .BR gets () と .BR fgets () は、成功すると .I s を返し、エラーや 1 文字も読み込んでいないのにファイルの終わりになった 場合に NULL を返す。 .PP .\"O .BR ungetc () .\"O returns .\"O .I c .\"O on success, or .\"O .B EOF .\"O on error. .BR ungetc () は成功すると .I c を返し、エラーの場合は .B EOF を返す。 .\"O .SH "CONFORMS TO" .SH 準拠 C89, C99, POSIX.1-2001. .\"O LSB deprecates .\"O .BR gets (). LSB では .BR gets () は非推奨である。 .\"O POSIX.1-2008 removes the specification of .\"O .BR gets (). POSIX.1-2008 では .BR gets () の仕様が削除されている。 .\"O .SH "BUGS" .SH バグ .\"O Never use .\"O .BR gets (). .\"O Because it is impossible to tell without knowing the data in advance how many .\"O characters .\"O .BR gets () .\"O will read, and because .\"O .BR gets () .\"O will continue to store characters past the end of the buffer, .\"O it is extremely dangerous to use. .\"O It has been used to break computer security. .\"O Use .\"O .BR fgets () .\"O instead. .BR gets () は絶対に使用してはならない。 前もってデータを知ることなしに .BR gets () が何文字読むかを知ることはできず、 .BR gets () がバッファの終わりを越えて書き込み続けるため、 .BR gets () を使うのは極めて危険である。 これを利用してコンピュータのセキュリティが破られてきた。 代わりに .BR fgets () を使うこと。 .PP .\"O It is not advisable to mix calls to input functions from the .\"O .I stdio .\"O library with low-level calls to .\"O .BR read (2) .\"O for the file descriptor associated with the input stream; the results .\"O will be undefined and very probably not what you want. 入力ストリームのファイルディスクリプタに対して、 .I stdio ライブラリの入力関数と、低レベル呼び出しの .BR read (2) を混ぜて呼び出す事は勧められない。 結果がどうなるかは分からず、おそらくあなたの 望んでいる結果にはならないだろう。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR read (2), .BR write (2), .BR ferror (3), .BR fgetwc (3), .BR fgetws (3), .BR fopen (3), .BR fread (3), .BR fseek (3), .BR getline (3), .BR getwchar (3), .BR puts (3), .BR scanf (3), .BR ungetwc (3), .BR unlocked_stdio (3)