首页 > 技术文章 > C 语言中的 feof()函数

sylar5 2017-03-29 09:44 原文

功能:

feof 是 C 语言标准库函数函数,其原型在 stdio.h 中,其功能是检测流上的文件结束符,如果文件结束,则返回非0值,否则返回0,文件结束符只能被 clearerr() 清除。

 

用法:

int feof(FILE *stream);    // *stream(流) :FILE结构的指针
 
例子:
#include<stdio.h>
int main(void)
{
    FILE *stream;
    /*openafileforreading*/
    stream = fopen("DUMMY.FIL", "r");
    /*readacharacterfromthefile*/
    fgetc(stream);
    /*checkforEOF*/
    if(feof(stream))
        printf("We have reached the end of file\n");
    /*closethefile*/
    fclose(stream);
    return 0;
}

详细解释:百度百科

推荐阅读