![]() |
| | #1 |
| Registered User Join Date: Oct 2005
Posts: 19
| Need help with input streams from multiple source files What I'm having trouble with is i get what looks like an infinite loop. I'm able to output the name and average of each file just fine, but after that, nothing happens, it seems to be trying to get input that isnt there. Im using Gnu on a unix system Any help would be appreciated, thanks! Code: infile1.open("master_file")
while(!infile1.eof())
{
infile1.getline(string, 80, '\n');
cout<<string<<endl;
infile2.open(string);
for(line=0;line<1;line++)
{
infile2.getline(name, 80, '\n'); //get name
cout<<name<<endl;
infile2>>score;
/*-----------------while(!infile2.eof()) //get score
{
total+=score;
num++;
infile2>>score;
} ------------------------Gets stuck in this loop*/
cout<<total/num<<endl;
}
infile2.close();
infile2.clear();
total=num=0;
}
infile1.close();
infile2.clear();
|
| orikon is offline | |
| | #2 |
| Registered User Join Date: Jan 2005
Posts: 7,252
| I'm not sure if this is your problem, but if the infile2 file stream goes into a fail state, that loop will go forever because you are only checking for eof(). A better way to do that loop is to put the read into the control of the while loop. Instead of this: Code: infile2>>score;
while(!infile2.eof()) //get score
{
total+=score;
num++;
infile2>>score;
}
Code: while(infile2>>score) //get score
{
total+=score;
num++;
}
|
| Daved is offline | |
| | #3 |
| Registered User Join Date: Oct 2005
Posts: 19
| Thank you so much, it's working now You saved me a lot of time, really appreciate it |
| orikon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Splitting source into multiple files(Linux & make) | IceDane | C Programming | 6 | 05-18-2009 07:31 AM |
| Mutex across multiple source files | Quasar | Linux Programming | 7 | 12-04-2007 08:25 AM |
| pseudocode for multiple source files | Calef13 | C++ Programming | 4 | 11-13-2007 09:07 AM |
| WM_COPYDATA and mutex selecting multiple files | gh0st | Windows Programming | 2 | 10-27-2006 02:22 PM |
| Beginner Question: Multiple source files | ironfistchamp | C++ Programming | 8 | 07-16-2006 02:19 PM |