c语言feof函数_使用示例的C语言中的feof()函数

c语言feof函数

C语言中的feof()函数 (feof() function in C)

Prototype:

原型:

    int feof(FILE* filename);

Parameters:

参数:

    FILE *filename

Return type: int(0 or 1)

返回类型: int(0或1)

Use of function:

使用功能:

In C language when we are using a stream that links with a file, then how can we determine we come to the end of a file. To solve the problem we have to compare an integer value to the EOF value. Through the feof() function we determine whether EOF of a file has occurred or not. The prototype of this function is int feof(FILE* filename);

在C语言中,当我们使用与文件链接的流时,那么如何确定到文件末尾。 为了解决该问题,我们必须将整数值与EOF值进行比较。 通过feof()函数,我们确定文件的EOF是否发生。 该函数的原型是int feof(FILE * filename);

It returns the value zero when end of the file has not occurred, otherwise it returns 1.

未出现文件结尾时,它返回零值;否则返回1。

feof()在C中的示例 (feof() example in C)

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

int main()
{
	FILE *f;
	char str[100];
	
	//Check the existence of that file
	if((f=fopen("includehelp.txt","r"))==NULL){
		printf("Cannot open the file...");
		//if not exist program is terminated
		exit(1);
	}
	
	printf("File content is--\n");
	//print the strings until EOF is encountered
	while(!feof(f)){
		fgets(str,100,f);
		//print the string
		printf("%s",str);
	}
	
	//close the opened file
	fclose(f);
	
	return 0;
}

Output

输出量

feof example in c

翻译自: https://www.includehelp.com/c-programs/feof-function-in-c-language-with-example.aspx

c语言feof函数

  • 5
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值