Thread: Parsing parameters from a text file in a random order

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    19
    Thanks for the tip Dave. This combo works fine indeed.

    Code:
    while ( fgets(buffer, 1024, in) )
    {
       // the first condition will fail so the second will be discarded automatically
       if ( widthRead == 0 && sscanf(buffer, "Width:%d",  &gContext.width) == 1 )
          widthRead = !widthRead;
       else if ( heightRead == 0 && sscanf(buffer, "Height:%d", &gContext.height) == 1 )
          heightRead = 1;
       else if ( initXYRead == 0 && sscanf(buffer, "InitXY(%d,%d)", &gContext.initX, &gContext.initY) == 2 )
          initXYRead = 1;
       else if ( CColRead == 0 && sscanf(buffer, "CCol:(%f,%f,%f)", &gContext.CCol.r, &gContext.CCol.g, &gContext.CCol.b) == 3 )
          CColRead = 1;
       else if ( i<10 && sscanf(buffer, "RGB(%f,%f,%f)", &gContext.preCol[i].r, &gContext.preCol[i].g, &gContext.preCol[i].b) == 3 )
          i++;}
    }
    I wonder why the other piece of code didn't work...
    This solution does what it was designed to do, however it seems like an overkill to me (even though I can't think of a more elegant solution).

    Duetti
    Last edited by Duetti; 11-20-2003 at 05:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Reading random line from a text file
    By helloamuro in forum C Programming
    Replies: 24
    Last Post: 05-03-2008, 10:57 PM
  3. Read word from text file (It is an essay)
    By forfor in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 11:45 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM