Advertisement

Odd problem...

Started by May 22, 2002 04:09 PM
0 comments, last by Ragadast 22 years, 6 months ago
I''m using BC++. I got an odd problem on loading info from text files. I do this: text file: blah blah blah blah blah blah blah 2 0 0 3 1 0 0 0 0 The first 2 lines correspond to the name and the description of the room. The 4 next lines corresponde to the exits, and the rest correspond to the items on the room. I do this to load it: ifstream infile("1.rom"); infile.getline(name, 50); //Name of the room infile.getline(desc, 255); //Description of the room infile >> room.exits[0]; //Room link to north exit infile >> room.exits[1]; //Room link to south exit infile >> room.exits[2]; //Room link to east exit infile >> room.exits[3]; //Room link to west exit infile >> room.objects[0]; //First object infile >> room.objects[1]; //etc... infile >> room.objects[2]; infile >> room.objects[3]; infile >> room.objects[4]; infile.close() Well, when i print out the info i got from loading my text file It confuses 2 variables: room.exits[3] and room.objects[0]. room.exits[3] gets the value of room.objects[0], making mistakes on my game. I dont get what happened.
Let me guess... the declaration of exits in your class is int exits[3] instead of int exits[4], and is followed by int objects[5]...

Since the exits array has only 3 elements, the address of exits[3] is the same as that of objects[0].

QED.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement