C library functions - feof ()
C standard library - <stdio.h>
description
C library functionsint feof (FILE * stream) test given flow stream end of file identifier.
statement
Here is the feof () function's declaration.
int feof(FILE *stream)
parameter
- stream - This is a pointer to FILE pointer to an object, the object identifier FILE flow.
return value
When setting up the stream associated with the end of file identifier, the function returns a non-zero value, otherwise it returns zero.
Examples
The following example demonstrates the feof () function is used.
#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); }
Suppose we have a text filefile.txt, its contents are shown below.The document will serve as our example program using an input:
这里是 w3cschool.cc
Let's compile and run the above program, which will result in the following:
这里是 w3cschool.cc