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
输出量
翻译自: https://www.includehelp.com/c-programs/feof-function-in-c-language-with-example.aspx
c语言feof函数