Re: How to put comments in initialization file read by fscanf()?

Discussion in 'C Programming' started by Chris Torek, Jul 14, 2003.

  1. Chris Torek

    Chris Torek Guest

    In article <> <> wrote:
    >I use the following code fragment to read variable names and values
    >from a file:
    > while(1) {
    > fscanf(file, "%s %s", name, value);
    > if(feof(file))
    > break;


    This loop runs forever on my file on a bad floppy. Why?

    (Hint: feof(file) is never true, even if fscanf() returns EOF,
    while ferror(file) is sometimes true.)

    (Someone else already suggested using fgets() and testing its
    result against NULL, which will do the trick.)
    --
    In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://67.40.109.61/torek/index.html (for the moment)
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Jul 14, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Rubin
    Replies:
    0
    Views:
    441
    David Rubin
    Jul 14, 2003
  2. Blankdraw

    Can't read entire record - fscanf (choked up)

    Blankdraw, Aug 25, 2003, in forum: C Programming
    Replies:
    2
    Views:
    536
    Eric Sosman
    Aug 27, 2003
  3. CJ

    fscanf to read lines from file?

    CJ, May 20, 2004, in forum: C Programming
    Replies:
    2
    Views:
    2,991
    Dan Pop
    May 21, 2004
  4. Replies:
    7
    Views:
    467
    Default User
    Sep 5, 2006
  5. Matrixinline

    fscanf to read string between " mark

    Matrixinline, May 29, 2008, in forum: C Programming
    Replies:
    1
    Views:
    1,016
    Jens Thoms Toerring
    May 29, 2008
Loading...

Share This Page