View Single Post
SlowToady SlowToady is offline
Registered
 
Join Date: Dec 2002
Location: www.fakelife.com
Posts: 1,672
Send a message via AIM to SlowToady
Got it figured out. What was happening with the original loop is that the variable count, declared as a short, would keep counting after reading the 10 entries from the file because, since it isn't entering the IF loops, it's not actually _reading_ from the file, so it continues forever. Actually, it continues until "count" reaches 32767, which is the upper limit of a short, then it rolls over to some negative value (-1 I think) and crashes the program with Memory Access Violations. Am now using "unsigned short count = 0" since the value of count since the value shouldn't ever go negative. Also, have the loop fixed. It is now:

Code:
unsigned short count = 0;
fin.open(filename.c_str());
//file checking is done here, no reason to show it

//priming read
fin >> Brand[count] >> RAM[count];

while (fin)
{
     count++;
     if (count < MAX_COMPUTER)
     {
           fin >> Brand[count] >> RAM[count];
     }
     else 
     {
           break;
     }
}
//close files, cleanup
return count;
}
Much thanks to my Brother in Law for pointing out that I'm a dolt:-D
__________________
I turn away with fear and horror from this lamentable sore of continuous functions without derivatives. --Charles Hermite

Fakelife.com Nothing to do with archery anymore. Porsche/BMW/Ferrari/Honda videos
Old 09-06-2007, 08:18 PM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #3 (permalink)