Reading in variables from a struct (ifstream)

For some reason I can't read these stats into my program. Basically the beginning of this assignment is just to open two files and read in the stats into the the program, but for some reason I keep getting into an infinite loop. The each row in the file is a different player (little league baseball), but I can only get the stats for the first one (playerList[0]). Anybody have any insight as to what might be wrong with my code? And this is just for the first file called masterFile for now.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>


using namespace std;

struct statStruct{
	
	string playerId;
	string firstName;
	string lastName;
	string division;
	string team;
	int plateApp;
	int atBats;
	int singles;
	int doubles;
	int triples;
	int homerun;
	int sac;
	int walks;
	int hitPitch;
	double batAvg;
	double basePerc;
	double slugPerc;
	string recordType;
};

int main()
{

	statStruct playerList[500];
	int n = 0;


	ifstream masterFile;
	masterFile.open("Master_Data (2).csv");

	if (masterFile.is_open())
	{
		while (!masterFile.eof())
		{
			getline(masterFile, playerList[n].playerId, ',');
			getline(masterFile, playerList[n].firstName, ',');
			getline(masterFile, playerList[n].lastName, ',');
			getline(masterFile, playerList[n].division, ',');
			getline(masterFile, playerList[n].team, ',');
			masterFile >> playerList[n].plateApp;
			masterFile.ignore(1);
			masterFile >> playerList[n].atBats;
			masterFile.ignore(1);
			masterFile >> playerList[n].singles;
			masterFile.ignore(1);
			masterFile >> playerList[n].doubles;
			masterFile.ignore(1);
			masterFile >> playerList[n].triples;
			masterFile.ignore(1);
			masterFile >> playerList[n].homerun;
			masterFile.ignore(1);
			masterFile >> playerList[n].sac;
			masterFile.ignore(1);
			masterFile >> playerList[n].walks;
			masterFile.ignore(1);
			masterFile >> playerList[n].hitPitch;
			masterFile.ignore(1);
			masterFile >> playerList[n].batAvg;
			masterFile.ignore(1);
			masterFile >> playerList[n].basePerc;
			masterFile.ignore(1);
			masterFile >> playerList[n].slugPerc;
			masterFile.ignore(1);
			n++;
		/*	if (n = 2)
			break;*/
			}
		}
		

	//for (int x = 0; x < n; x++)
	//{
	//	cout << playerList[x].playerId << endl;
	//}
	statStruct updatePlayers[500]; 
		int i = 0;

		ifstream leagueFile;
		leagueFile.open("2014_League_Stats_v2.csv", ios::in); //opening 2014 league file
		if (leagueFile.is_open())
		{

			while (!leagueFile.eof())
			{
				getline(leagueFile, updatePlayers[i].recordType, ',');
				getline(leagueFile, updatePlayers[i].playerId, ',');
				getline(leagueFile, updatePlayers[i].firstName, ',');
				getline(leagueFile, updatePlayers[i].lastName, ',');
				getline(leagueFile, updatePlayers[i].division, ',');
				getline(leagueFile, updatePlayers[i].team, ',');
				leagueFile >> updatePlayers[i].plateApp;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].atBats;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].singles;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].doubles;
				leagueFile.ignore();
				leagueFile >> updatePlayers[i].triples;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].homerun;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].sac;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].walks;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].hitPitch;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].batAvg;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].basePerc;
				leagueFile.ignore(1);
				leagueFile >> updatePlayers[i].slugPerc;
				leagueFile.ignore(1);

				i++;

			}
		}
	

	system("pause");
	return 0;
}

Last edited on
Topic archived. No new replies allowed.