请问feof函数和ferror函数有什么区别?谢谢

如题所述

第1个回答  2009-05-08
一、文件结束检测函数feof函数调用格式: feof(文件指针);
功能:判断文件是否处于文件结束位置,如文件结束,则返回值为1,否则为0。

二、读写文件出错检测函数ferror函数调用格式: ferror(文件指针);
功能:检查文件在用各种输入输出函数进行读写时是否出错。 如ferror返回值为0表示未出错,否则表示有错。
第2个回答  推荐于2016-08-03
feof
Tests for end-of-file on a stream.

ferror
Tests for an error on a stream.

example:
/* FEOF.C: This program uses feof to indicate when
* it reaches the end of the file FEOF.C. It also
* checks for errors with ferror.
*/

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

void main( void )
{
int count, total = 0;
char buffer[100];
FILE *stream;

if( (stream = fopen( "feof.c", "r" )) == NULL )
exit( 1 );

/* Cycle until end of file reached: */
while( !feof( stream ) )
{
/* Attempt to read in 10 bytes: */
count = fread( buffer, sizeof( char ), 100, stream );
if( ferror( stream ) ) {
perror( "Read error" );
break;
}

/* Total up actual bytes read */
total += count;
}
printf( "Number of bytes read = %d\n", total );
fclose( stream );
}

Output

Number of bytes read = 745本回答被提问者采纳
第3个回答  2009-05-08
1 文件结束检测函数feof函数
调用格式:
feof(文件指针);
功能:判断文件是否处于文件结束位置,如文件结束,则返回值为1,否则为0。
2 读写文件出错检测函数
ferror函数调用格式:
ferror(文件指针);
功能:检查文件在用各种输入输出函数进行读写时是否出错。如ferror返回值为0表示未出错,否则表示有错。
.3 文件出错标志和文件结束标志置0函数
clearerr函数调用格式:
clearerr(文件指针);
功能:本函数用于清除出错标志和文件结束标志,使它们为0值。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网