Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 




feof() - I/O Function


Tutorials Cpp

Topic

How is feof() used in C++?
How to check file position indicator for EOF?



Explanation

feof() is an I/O function that checks the file position indicator for the EOF of the associated stream. This check end of file indicator is generally set by a previous operation on the stream that reached the End-of-File. This function returns a non zero value if the EOF is reached, otherwise "0" is returned.

Syntax:
    int feof ( FILE * stream );
Example:

   #include <stdio.h>
   int main()
    {
      long count = 0;
      FILE * stri = fopen ("getceg.txt", "r");
      if( ferror(stri) ) 
          {
            perror( "Error in File" );
           }
      while (!feof (stri)) 
          {
            fgetc (stri); 
            count++;
          }
      fclose (stri);
      printf  ("Total bytes read in the file: %d\n", count-1);
      return 0;
    }

Result:
    Total bytes read in the file: 11

In the above example the "feof()" is used to find the total number of bytes read in a text file. The content of the text file is "ABCA1@@ABNM".










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting