fgetc

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

fgetc, fgets, getchar, ungetc - input of characters and strings  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <stdio.h>

int fgetc(FILE *stream);
int getchar(void);

char *fgets(int size;
            char s[restrict size], int size, FILE *restrict stream);

int ungetc(int c, FILE *stream);
 

説明

fgetc() は、 stream から次の文字を unsigned char として読み、 int にキャストして返す。ファイルの終わりやエラーとなった場合は EOF を返す。

getchar() is equivalent to fgetc(stdin).

fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte ('\0') is stored after the last character in the buffer.

ungetc() は、後の read 操作で読めるように、 c を unsigned char にキャストして stream に書き戻す。 書き戻された文字は逆順に戻される; 書き戻しとして保証されているのは、一文字だけである。

ここで述べた関数や stdio ライブラリの入力関数を同じ入力ストリームに対して互いに混ぜて使うことができる。

これらの処理を停止せずに行いたいときは、 unlocked_stdio(3) を参照のこと。  

返り値

fgetc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error.

fgets() は、成功すると s を返し、エラーや 1 文字も読み込んでいないのにファイルの終わりになった 場合に NULL を返す。

ungetc() は成功すると c を返し、エラーの場合は EOF を返す。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
fgetc(), fgets(), getchar(), ungetc() Thread safetyMT-Safe
 

標準規格

C11, POSIX.1-2008.  

歴史

POSIX.1-2001, C89.  

注意

入力ストリームのファイルディスクリプターに対して、 stdio ライブラリの入力関数と、低レベル呼び出しの read(2) を混ぜて呼び出す事は勧められない。 結果がどうなるかは分からず、おそらくあなたの 望んでいる結果にはならないだろう。  

関連項目

read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3), fseek(3), getline(3), gets(3), getwchar(3), puts(3), scanf(3), ungetwc(3), unlocked_stdio(3), feature_test_macros(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
注意
関連項目

This document was created by man2html, using the manual pages.