C Programming: Keep reading a text file even if there is a blank line

Discussion in 'Mac Programming' started by francis21, Feb 13, 2012.

  1. francis21 macrumors member

    May 2, 2011
    Mississauga, ON, Canada
    Hey guys, with the assignment that I'm currently working on I have words that I need to place in a char *buffer variable. I'm using the fgets() function to achieve this goal.

    Here is a sample data of the file:


    Note that the new line between the words skin and skirt are intentional. The problem that I'm encountering is how to keep reading that next word since its not really the end of file yet. Thanks for the help guys!
  2. lloyddean macrumors 6502a

    May 10, 2009
    Des Moines, WA
    We can't help if you don't post the code along with the problem.
  3. KnightWRX macrumors Pentium


    Jan 28, 2009
    Quebec, Canada
    Did you search on Google ? Found plenty of code snippets and solutions by simply searching for "C read until end of file". What did you try searching for ?

    For C Programming, I suggest just going to comp.lang.c's wonderful FAQ that should answer any questions you may have. Faster than doing forum posts with close to 0 details.

    It really depends on how you're doing input. If using fgets(), check the return value instead of the contents of the buffer. If using getchar() try to see if there's a constant that might indicated the End-Of-File marker (big hint in bold there). Check to see if there's any functions that can indicate a File's End-Of-File () marker was reached (again, big hint in bold).

Share This Page