Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

francis21

macrumors member
Original poster
May 2, 2011
82
2
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:
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!
 
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).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.