Thread: Differences between EOF and feof() in FILES and at all plus clarification

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    96

    Differences between EOF and feof() in FILES and at all plus clarification

    Good day! I saw a thread about "foef" and "EOF", and since the post were short and clear I like to ask for something.

    When should we use "feof ()"?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    feof() reads the internal state of the stream and returns something non-zero if the end-of-file is set. This state is set by all input functions such as fgets(), fscanf(), etc. Sometimes these can fail before reaching the end, in case of a file error for example. If you're looping by using the return value of fscanf(), with feof() you could check if you actually reached the end of the file before exiting and either try again or print an error message.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Differences between EOF and feof() in FILES
    By RyanC in forum C Programming
    Replies: 5
    Last Post: 03-22-2016, 05:22 AM
  2. while(!feof(f))...
    By catasturslykid in forum C Programming
    Replies: 5
    Last Post: 08-23-2013, 12:37 PM
  3. while(!feof)
    By mconflict in forum C Programming
    Replies: 12
    Last Post: 04-02-2012, 12:30 PM
  4. cannot get out of while( !feof (f) )
    By SoFarAway in forum C Programming
    Replies: 2
    Last Post: 02-19-2005, 03:36 PM
  5. feof()
    By XSquared in forum C Programming
    Replies: 2
    Last Post: 06-02-2004, 12:16 AM

Tags for this Thread