Thread: problems with "if" 's, files, and do's. please help

  1. #1
    Unregistered
    Guest

    problems with "if" 's, files, and do's. please help

    this chunk of code displys NOTHING why is that?
    char data[50];


    do
    {
    fin>>data;
    if(data == "{title")
    {
    fin>>data;
    cout << data << endl;
    }
    if(data == "{zdescription")
    {
    do
    {
    if(i == 0)
    {
    fin>>data;
    i=1;
    }
    cout << data << endl;
    fin>>data;
    } while(data != "}zdescription");
    i = 1;
    }
    if(data == "{exits")
    {
    fin>>up;
    fin>>down;
    fin>>north;
    fin>>south;
    fin>>east;
    fin>>west;
    cout << "Exits[ ";
    if(up != 0)
    cout << "-up ";
    if(down != 0)
    cout << "-down ";
    if(north != 0)
    cout << "-north ";
    if(south != 0)
    cout << "-south ";
    if(east != 0)
    cout << "-east ";
    if(west != 0)
    cout << "-west ";
    if((up == 0) && (down == 0) && (north == 0) && (south == 0) && (east == 0) && (west == 0))
    cout << "None! ";
    cout << "]" << endl;
    }
    } while(data != "}");



    This is an infinate do and i do not know why, It also does not display ANYTHING... Here is the file that it reads:

    }
    {title
    hole of incarnation
    }title
    {zdescription
    you are in hole surrounded by lifeless bodys, waiting to be awakend...
    }zdescription
    {exits
    3
    0
    0
    0
    0
    0
    }exits
    {items
    }items
    {mobs
    }mobs
    {specials
    }specials
    }

    What is wrong here???? (I am use microsoft visual C++)

  2. #2
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536

    Re: problems with "if" 's, files, and do's. please help

    Originally posted by Unregistered
    this chunk of code displys NOTHING why is that?

    Code:
    char data[50];
    
    
    do
    {
      fin>>data;
      if(data == "{title")
      {
        fin>>data;
        cout << data << endl;
      }
      if(data == "{zdescription")
      {
        do
          {
            if(i == 0)
            {
              fin>>data;
              i=1;
              }
            cout << data << endl;
            fin>>data;
            } while(data != "}zdescription");
          i = 1;
          }
        if(data == "{exits")
        {
          fin>>up;
          fin>>down;
          fin>>north;
          fin>>south;
          fin>>east;
          fin>>west;
          cout << "Exits[ ";
          if(up != 0)
            cout << "-up ";
          if(down != 0)
            cout << "-down ";
          if(north != 0)
            cout << "-north ";
          if(south != 0)
            cout << "-south ";
          if(east != 0)
            cout << "-east ";
          if(west != 0)
            cout << "-west ";
          if((up == 0) && (down == 0) && (north == 0) && (south == 0) && (east == 0) && (west == 0))
            cout << "None! ";
          cout << "]" << endl;
        }
      } while(data != "}");
    This is an infinate do and i do not know why, It also does not display ANYTHING... Here is the file that it reads:

    }
    {title
    hole of incarnation
    }title
    {zdescription
    you are in hole surrounded by lifeless bodys, waiting to be awakend...
    }zdescription
    {exits
    3
    0
    0
    0
    0
    0
    }exits
    {items
    }items
    {mobs
    }mobs
    {specials
    }specials
    }

    What is wrong here???? (I am use microsoft visual C++)
    OK, now we can get a better look at it
    Last edited by TravisS; 06-21-2002 at 04:36 PM.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    22

    couple things ur doing wrong

    First off I'm new, so everything I say may be untrue. I'm just trying to help.

    ----------------------------------------

    Code:
     
    fin>>data;
    try using cin>>data; instead. that's fin with a "c".

    ----------------------------------------

    Code:
    if(data == "{title")
    try not using quotation marks, or a { symbol. like:

    Code:
    int title // make sure that you have initialized all variables.
    if(data == title)
    ----------------------------------------

    that should help, just use those two problem sovlers for ur code over and over, and hopefully it will help.

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Code:
    fin>>data
    this will read a single char from the file. use fin.getline(data,size);
    size -> means data[size]

    Code:
    if(data == "{title")
    use if(strcmp(data,"{title")==0)
    0 means matching/same.


    Code:
    fin>>data;
      if(data == "{title")
      {
        fin>>data;
        cout << data << endl;
      }
    what this piece does is : read 1 char from file, compare that single char to {title [which btw is not correct] and then if the comparision is correct read another single char and display it on screen [are you sure this is what you want]

    i think your whole code which is posted here will have to be re-written to accomodate the changes.
    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  2. Copying system files problems
    By Dark Nemesis in forum Tech Board
    Replies: 11
    Last Post: 03-24-2004, 01:06 AM
  3. files > 65535 bytes wont read in dos
    By Pharoh in forum C Programming
    Replies: 4
    Last Post: 11-11-2003, 11:51 AM
  4. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM
  5. reading old dos binary files
    By ronin in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-10-2001, 12:43 PM