NFL File Generation

I am trying to generate a file that will output every possible outcome of an NFL game in this format:
<team abbreviation> + <score> + "&" + <other team abbreviation> + <other score>
eg: ari7&atl3
so the file would look like when my program is executed:

ari0&ari0
ari0&ari1
ari0&ari2
...
ari0&atl0
...
was100&was100

this is the code and im not sure why it doesnt work...

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
#include <iostream>
#include <stdio.h>
#include <string.h>
#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())
	{
		int count = 0;
		int count2 = 0;
		infile.getline (buffer,100);
		while(count <= 100)
		{
			while(! infile2.eof())
			{
				infile2.getline (buffer2,100);
				while(count2 <= 100)
				{
				outfile << buffer << count << "&" << buffer2 << count2 << endl;
				count2++;
				}
			}
		count++;
		}
	}
	infile.close();
	infile2.close();
	outfile.close();
	return 0;
}


it compiles but doesnot run like i want it to...
the file with all the nfl acronyms is:

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
ARI
ATL
BAL
BUF
CAR
CHI
CIN
CLE
DAL
DEN
DET
GB
HOU
IND
JAX
KC
MIA
MIN
NE
NO
NYG
NYJ
OAK
PHI
PIT
SD
SEA
SF
STL
TB
TEN
WAS


this is not a school assignment...thanks :D
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



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
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
wait i would need to reset both int's after they reached a hundred right?
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
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 :/
Topic archived. No new replies allowed.