#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Chicago
    Posts
    14
    Rep Power
    0

    Lightbulb 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.

    Thanks
    :rolleyes:
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,594
    Rep Power
    4207
    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
  4. #3
  5. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    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).
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I believe getline() is for C++, the poster requested C code.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Poland
    Posts
    57
    Rep Power
    11
    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.

IMN logo majestic logo threadwatch logo seochat tools logo