目录

int feof(FILE *stream)

描述 (Description)

C库函数int feof(FILE *stream)测试给定流的文件结束指示符。

声明 (Declaration)

以下是feof()函数的声明。

int feof(FILE *stream)

参数 (Parameters)

  • stream - 这是指向标识流的FILE对象的指针。

返回值 (Return Value)

当设置与流关联的End-of-File指示符时,此函数返回非零值,否则返回零。

例子 (Example)

以下示例显示了feof()函数的用法。

#include <stdio.h>
int main () {
   FILE *fp;
   int c;
   fp = fopen("file.txt","r");
   if(fp == NULL) {
      perror("Error in opening file");
      return(-1);
   }
   while(1) {
      c = fgetc(fp);
      if( feof(fp) ) { 
         break ;
      }
      printf("%c", c);
   }
   fclose(fp);
   return(0);
}

假设我们有一个文本文件file.txt ,它有以下内容。 该文件将用作示例程序的输入 -

This is iowiki.com

让我们编译并运行上面的程序,这将产生以下结果 -

This is iowiki.com
↑回到顶部↑
WIKI教程 @2018