c语言ferror_使用示例的C语言中的ferror()函数

c语言ferror

C中的ferror()函数 (ferror() function in C)

Prototype:

原型:

    int ferror(FILE *filename);

Parameters:

参数:

    FILE *filename

Return type: int(0 or 1)

返回类型: int(0或1)

Use of function:

使用功能:

If in the last file operation there is some error introduced in that file, by the ferror() function we identify there is some error in that file during the last operation. The prototype of ferror() function is int ferror(FILE* filename);

如果在上一个文件操作中该文件中引入了一些错误,则通过ferror()函数,我们可以确定在上一个操作期间该文件中存在一些错误。 ferror()函数的原型是int ferror(FILE * filename);

But only detects the last operational error of the file because every time the error flag of the file is set.

但是只检测文件的最后操作错误,因为每次都设置文件的错误标志。

C中的ferror()示例 (ferror() 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);
	}

	// Check if here is some error in the file
	if(ferror(f))
		printf("Error to read the file\n");
	else	
		printf("No error in reading\n");

	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

输出量

ferror example in c

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

c语言ferror

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值