PDA

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




francis21
Feb 13, 2012, 04:46 PM
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:
silver
simple
sister
size
skin

skirt

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!



lloyddean
Feb 13, 2012, 05:00 PM
We can't help if you don't post the code along with the problem.

KnightWRX
Feb 13, 2012, 06:10 PM
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 (http://c-faq.com) 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).