User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:feof

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 <stdio.h> /* including standard library */
//#include <windows.h> /* 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

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/feof.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz