ファイル終端(終了)のチェックをします。
#include <stdio.h>
int feof(FILE *);
第1引数 : ファイル・ポインタ 戻り値 : 0:続きあり、0以外:ファイルの終端(終了)
#include <stdio.h> int main () { FILE *fp; char cText[256]; /* ファイル・オープン */ fp = fopen ("open.txt", "r"); if (fp != NULL) { /* ファイル終端チェック */ while (feof(fp) == 0) { /* 初期化 */ cText[0] = '\0'; /* ファイル読み出し */ fscanf (fp, "%s", cText); /* 表示 */ printf ("%s\n", cText); } /* ファイル・クローズ */ fclose (fp); } return (0); }
abcdefghijklmnopqrstuvwxyz 1234567890
$ ./eof abcdefghijklmnopqrstuvwxyz 1234567890