Jul 19, 2010 at 10:25am UTC
You need to reset the file pointer for infile2 to the beginning around line 23-24 and move the line
int count2=0;
inside the while loop at line 24
Jul 19, 2010 at 11:46am UTC
As Moooce said:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char buffer[256];
char buffer2[256];
string final;
ifstream infile ("list.txt" , ios::in);
ifstream infile2 ("list.txt" , ios::in);
ofstream outfile ("out.txt" , ios::trunc);
while (! infile.eof())
{
infile.getline (buffer,100);
int count = 0;
while (count <= 100)
{
infile2.seekg(0); // return to start of file
infile2.clear(); // clear EOF flag
while (! infile2.eof())
{
infile2.getline (buffer2,100);
int count2 = 0; // this should be here
while (count2 <= 100)
{
outfile << buffer << count << "&" << buffer2 << count2 << endl;
count2++;
}
}
count++;
}
}
infile.close();
infile2.close();
outfile.close();
return 0;
}
You might also consider using std::string rather than a char[] for your input.
1 2 3 4 5 6 7 8 9 10 11
#include <string>
// ... stuff ...
std::string line;
while (std::getline(infile, line))
{
// ... etc
}
Also you are going to generate quite a sizeable file there...
Last edited on Jul 19, 2010 at 11:47am UTC
Jul 19, 2010 at 8:32pm UTC
ok thanks so much that helped but after the first team it just does the first team as zero and doesnt change that so its always like
sd0&atl90
but the 0 never changes.
And yes i realize that the file will be massive...
also after it finishes it runs it twice and leaves off the second team
Jul 19, 2010 at 8:34pm UTC
wait i would need to reset both int's after they reached a hundred right?
Jul 19, 2010 at 8:43pm UTC
It works fine for me. The sd0 will not change from 0 until every team has moved from 0-100. So that would be 101 times the number of teams.
Try reducing the number of teams to about 4 and the number in the loops to about 10 for testing purposes.
Last edited on Jul 19, 2010 at 8:44pm UTC
Jul 19, 2010 at 8:50pm UTC
ok i see what happening...it runs through every team on ari0 then it goes all the way to 10 without using the other teams which is strange...
I feel like a real noob here and i assure you im not...sorry :/