I have a master file listing 15 subfiles in the same directory. Each of these files has a name in the top line, and 2 digit numbers in each subsequent line (about 5 lines). What I need to do is open each of those file names by calling it from the master file, and print the name (first line) to the screen in descending order, and calculate the average of the numbers.
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();