{{keywords>wiki library source code example reference}} ====== feof ====== int feof(FILE *stream); checks that are applied to a stream or data or the end-of-file indicator is set.\\ Used to determine if the end of the file (stream) specified, has been reached. When a file is being read sequentially one line, or one piece of data at a time (by means of a loop, say), this is the function you check every iteration, to see if the end of the file has come.\\ Returns non-zero if end-of-file indicator is set for stream stream. ===== C Sourcecode Example ===== /* * feof example code * http://code-reference.com/c/stdio.h/feof */ #include /* including standard library */ //#include /* uncomment this for Windows */ #define MAX 1000 int main( void ) { char buffer[MAX]; FILE *filestream; filestream = fopen("test.txt","r"); while (feof(filestream) == 0) { fgets(buffer, MAX, filestream); if (buffer[0] == '#') { continue; } else { printf("%s",buffer); } buffer[0]='\0'; } fclose(filestream); return 0; } content of **test.txt** Line 1 #Line 2 Line 3 #Line 4 Line 5 ==== feof output ==== user@host:~$ ./feof Line 1 Line 3 Line 5 ==== See also ==== [[c:stdio.h:clearerr|clearerr()]] [[c:stdio.h:ferror|ferror()]] [[c:stdio.h:perror|perror()]] [[c:stdio.h:putc|putc()]] [[c:stdio.h:getc|getc()]]