Thread: How to detect an empty file?

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    17

    How to detect an empty file?

    My program reads a .txt file.

    I want to check when the program detects a new line in a file. If the file is empty i, it assigns the word "Stable" to a string, if it detects a new line, the programs assign the word "Fail" to the string.

    I know how to read a line in a file, but just because the program is almost stable all the time, I don't want to write that word in to the file all the time. So when the other program writes to the file is because there is a problem.

    am I clear?

    Thanks a lot
    Daniel
    A Man can be whatever he wants to
    be

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    ummm... which OS?

    I think that you can check the size of a file with the Win32 API...
    Away.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    17
    I am Using Red Hat Linux 7.2
    A Man can be whatever he wants to
    be

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    you could open, seek to the "SEEK_SET" then see if that is EOF or not.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>. So when the other program writes to the file is because there is a problem.<<
    Are you trying to mimic tail -f ?

    If so, read the file until you hit EOF, then clear the file stream error settings, sleep a while and read again to see if there's new data in it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM