C 库函数 - feof()

C 语言教程 · 2019-02-23 13:57:10

描述

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

声明

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

int feof(FILE *stream)

参数

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

返回值

当设置了与流关联的文件结束标识符时,该函数返回一个非零值,否则返回零。

实例

下面的实例演示了 feof() 函数的用法。

#include <stdio.h>

int main ()
{
   FILE *fp;
   int c;
  
   fp = fopen("file.txt","r");
   if(fp == NULL) 
   {
      perror("打开文件时发生错误");
      return(-1);
   }
   while(1)
   {
      c = fgetc(fp);
      if( feof(fp) )
      { 
          break ;
      }
      printf("%c", c);
   }
   fclose(fp);
   return(0);
}

假设我们有一个文本文件 file.txt,它的内容如下所示。该文件将作为我们实例程序中的一个输入使用:

这里是 codercto.com

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

这里是 codercto.com

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

Coming of Age in Second Life

Coming of Age in Second Life

Tom Boellstorff / Princeton University Press / 2008-04-21 / USD 29.95

The gap between the virtual and the physical, and its effect on the ideas of personhood and relationships, is the most interesting aspect of Boellstorff's analysis... Boellstorff's portrayal of a virt......一起来看看 《Coming of Age in Second Life》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具