feof in c
feof in c programming language

If you are searching for feof in c then read this blog post completely.

What is feof in c?

feof in c is used to find end of a file for the given stream.

It is defined in stdio.h header.

EOF is completely different from feof.

This function returns non-zero value when end-of-file indicator is set otherwise zero is returned.

Prototype of feof

int feof(FILE *strm);

Return value of feof

This function returns non-zero value when end-of-file indicator is set otherwise zero is returned.

Parameters for feof

Here strm is a pointer to a file that identifies a stream.

Example program for feof in c programming language

#include <stdio.h>

int main () {
   FILE *fpointer;
   int ch;
  
   fpointer = fopen("scholar.txt","r");
   if(fpointer == NULL) {
      printf("\nError occured in opening file\n");
      return(-1);
   }
   
   while(1) {
      ch = fgetc(fpointer);
      if( feof(fpointer) ) { 
         break ;
      }
      printf("%c", ch);
   }
   fclose(fpointer);
   return(0);
}

Code explanation

feof is called to check whether the file pointer has reached to the end of file. If it is true then control jumps out of a loop.

feof() Man page


Difference between feof and fwrite.

feof in c is used to find end of a file for the given stream. fwrite is used to write binary data to a file.

feof returns a non-zero value when the end-of-file indicator is set otherwise zero is returned. fwrite returns the total number of items written in a file.

feof takes one argument. fwrite takes four arguments.

feof takes one pointer. fwrite takes two pointers where one pointer points to an array of elements to be written.

Prototypes are as follows

int feof(FILE *strm);

size_t fwrite(const void *pt,size_t size,size_t nmeb,FILE *strm);
feof in cfwrite in c
Used to find end of a file for the given stream.Used to write binary data to a file.
int feof(FILE *strm);
size_t fwrite(const void *pt,size_t size,size_t nmeb,FILE *strm);
Returns non-zero value when end-of-file indicator is set otherwise zero is returned.Returns total number of items written in a file.
Takes one argument.Takes four arguments.

Difference between fscanf and feof in c

fscanf in c used to read formatted data from a file. feof in c is used to find end of a file for the given stream.

fscanf returns the number of fields converted and assigned. If an error occurs it returns EOF. feof returns a non-zero value when the end-of-file indicator is set otherwise zero is returned.

fscanf takes many arguments. feof takes only one argument.

fscanf works as an input function. feof is used to obtain EOF in a file.

Prototypes are as follows

int fscanf(FILE *strm, const char *frmt,...);

int feof(FILE *strm);
feof in cfscanf in c
Used to find end of a file for the given stream.Used to read formatted data from a file.
int feof(FILE *strm);int fscanf(FILE *strm, const char *frmt,...);
Returns non-zero value when end-of-file indicator is set otherwise zero is returned.Returns the number of fields converted and assigned. If error occurs it returns EOF.
Takes only one argument.Takes many arguments.

Difference between fprintf and feof in c

fprintf function in c is used to format the output to a file instead of stdout console. feof in c is used to find the end of a file for the given stream.

fprintf returns the number of characters written. if any error occurs it returns a negative value(-1). feof returns a non-zero value when the end-of-file indicator is set otherwise zero is returned.

fprintf takes many arguments. feof takes only one argument.

fprintf works as output function. feof is used to find end of a file.

Prototypes are as follows

int fprintf(FILE *file_pointer, const  char *format_string,.......);

int feof(FILE *strm);
fprintf in cfeof in c
Used to format the output to a file instead of stdout console.Used to find end of a file for the given stream.
int fprintf(FILE *file_pointer, const char *format_string,.......);int feof(FILE *strm);
Returns the number of characters written.if any error occurs it returns negative value(-1).Returns non-zero value when end-of-file indicator is set otherwise zero is returned.
Takes many arguments.Takes only one argument.

Difference between fseek and feof in c

The fseek in c is used to change the file pointer for the specified stream. feof in c is used to find the end of a file for the given stream.

fseek returns zero if successful operation otherwise it returns a non-zero value. feof returns a non-zero value when the end-of-file indicator is set otherwise zero is returned.

fseek takes three arguments. feof takes one argument.

fseek takes the offset value depending upon argument SEEK_START, SEEK_CUR, SEEK_END value. feof takes the end of a file value.

Prototypes are as follows

int fseek(FILE *strm,long int offst,int whnce);


int feof(FILE *strm);
fseek in cfeof in c
Used to change the file pointer for the specified stream.Used to find end of a file for the given stream.
int fseek(FILE *strm,long int offst,int whnce);int feof(FILE *strm);
Returns zero if successful operation otherwise it returns a non-zero value.Returns non-zero value when end-of-file indicator is set otherwise zero is returned.
Takes three arguments.Takes one argument.

People also ask

What is the difference between ftell and feof in c?

ftell is used to find the total size of a file from the beginning of a file. feof is used to find the end of the file for a given stream.

What is the difference between EOF and feof in c?

EOF is a value to compare end of a file. feof is function to check end of a file.

What is the difference between fputs and feof in c?

fputs writes the array of characters to a given stream. feof takes the end of a file position in a given file.

What is the difference between fgetc and feof in c?

fgetc is used to take the next character in the stream. feof is used to take an end of a file position in a given file.

What does feof stands for?

feof stands for test end-of-a-file indicator in a stream. it is used to find end of a file.

What is the difference between fread and feof in c?

fread is used to read buffered data from a file. feof is used to take the end of file position in a given stream.

What is the difference between ferror and feof in c?

ferror function is used to test an error in a given stream while reading/writing. feof is used to take an end of a file in a given stream.