August 6th, 2003, 12:03 PM
read line by line from a file
How do I read line by line from a txt file.
Each line is variable in length with '\n' as the newline.
This is in C code.
August 6th, 2003, 12:46 PM
Try using the fgets() function.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
August 7th, 2003, 05:48 AM
Hmm, I thought fgets() was deprecated because of null reading issues. Not sure, but I'd also look into using getline().
Not all systems support it, so sometimes fgets is your only option (although you can write your own getline using fgets). I think it is also a tad more readable (it is obvious from the name alone what its intention is).
August 7th, 2003, 08:47 AM
I believe getline() is for C++, the poster requested C code.
August 7th, 2003, 09:37 AM
it's not hard to write such function using fopen and fgetc in C. There were at least 4 ways of doing this in "Language C" (or sth like that, dunno, I've got polish version), best book I've ever seen.