当前位置: C语言 -- 标准库 -- <stdio.h> -- EOF

EOF宏


概要:

#define EOF value //value值由具体实现定义。


描述:

该宏表示文件末尾,会扩展为int类型的负值整型常量表达式。

一些函数返回该宏表示文件末尾,即不再有来自流的输入。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
/*宏EOF范例*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE *pFile;
    int ch;
   
    /*打开文件。*/
    pFile = fopen("gch.txt", "r");
    if(pFile == NULL)
    {
        perror("Fail to open the file");
        exit(EXIT_FAILURE);
    }

    /*输出文件中的字符。*/
    while((ch=fgetc(pFile))!= EOF)
        fputc(ch, stdout);

    /*关闭文件。*/
    fclose(pFile);

    return 0;
}


结果:

将输出gch.txt文件中的字符。


相关内容:
feof 测试文件末尾指示符的函数。