当我将数组传递出函数时,我的数组被视为变量。我尝试过多次修复,但似乎都没有。在ReadInRound函数中,文件中的所有内容都会写出我正在读取的文件。我想将Update []数组带到Append函数中,这样我就可以附加我正在写的文件。
struct MasterFile{
string round, ID, fName, lName, league, team;
double mins, twoPTA, twoPTM, threePTA, threePTM, fTA, fTM, perTwo, perThree, perFT, fouls, turnovers, points;};
struct Header{
string record, fileName, date, round;};
struct Footer{
string record, fileName, date, round;
int recordCount;
double mins;};
struct UpdateFile{
string record, action, round, ID, fName, lName, league, team;
double mins, twoPTA, twoPTM, threePTA, threePTM, fTA, fTM, fouls, turnovers, points;};
int main(){
Header header[1];
Footer footer[500];
MasterFile Master[500];
UpdateFile Update[500];
MasterFile NewMaster[500];
int x = 0; // Round counter
double roundCount = 0;
int u = 0; // New master counter
int w = 0;
x = ReadInRound(Update, Master);
ReadInMaster();
Append(roundCount, Master, Update, x, NewMaster);
Out(w, NewMaster, u);
system("Pause");
return 0;}
double ReadInRound(UpdateFile Up[], MasterFile Master[]){
ifstream RoundFile;
RoundFile.open("roundData.txt", ios::in);
string recordType = "H,D,T";
double points = 0.0;
Header header[1];
Footer footer[500];
UpdateFile Update[500];
int x = 0;
if (RoundFile.is_open())
{//Header
getline(RoundFile, header[x].record, ',');
getline(RoundFile, header[x].fileName, ',');
getline(RoundFile, header[x].date, ',');
getline(RoundFile, header[x].round, '\n');
x++;
while (!RoundFile.eof())
{//Player Data
getline(RoundFile, recordType, ',');
if (recordType == "T")
{//Footer
//footer[x].record = recordType;
getline(RoundFile, footer[x].record, ',');
getline(RoundFile, footer[x].fileName, ',');
getline(RoundFile, footer[x].date, ',');
getline(RoundFile, footer[x].round, ',');
RoundFile >> Update[x].points;
RoundFile.ignore(100, '\n');
x++;
break;
}
Update[x].record = recordType;
getline(RoundFile, Update[x].action, ',');
getline(RoundFile, Update[x].round, ',');
getline(RoundFile, Update[x].ID, ',');
getline(RoundFile, Update[x].fName, ',');
getline(RoundFile, Update[x].lName, ',');
getline(RoundFile, Update[x].league, ',');
getline(RoundFile, Update[x].team, ',');
RoundFile >> Update[x].mins;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].twoPTA;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].twoPTM;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].threePTA;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].threePTM;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].fTA;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].fTM;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].fouls;
RoundFile.ignore(100, ',');
RoundFile >> Update[x].turnovers;
RoundFile.ignore(100, '\n');
points = (Update[x].twoPTM * 2) + (Update[x].threePTM * 3) + (Update[x].fTM * 1);
x++;
}
//Up = Update;
}
else
{
cout << "Round File failed to open.\n";
}
return x;}
void Append(double& roundCount, MasterFile Master[], UpdateFile Update[], int& x, MasterFile NewMaster[]){
int w = 0;
for (int d = 0; d < x; d++)
{
int e = 0;
if (Master[e].ID == Update[d].ID)
{
if (Update[d].action == "C")
{
NewMaster[w].ID = Update[d].ID;
NewMaster[w].fName = Update[d].fName;
NewMaster[w].lName = Update[d].lName;
NewMaster[w].league = Update[d].league;
NewMaster[w].team = Update[d].team;
NewMaster[w].mins = Master[e].mins + Update[d].mins;
NewMaster[w].twoPTA = Master[e].twoPTA + Update[d].twoPTA;
NewMaster[w].twoPTM = Master[e].twoPTM + Update[d].twoPTM;
NewMaster[w].threePTA = Master[e].threePTA + Update[d].threePTA;
NewMaster[w].threePTM = Master[e].threePTM + Update[d].threePTM;
NewMaster[w].fTA = Master[e].fTA + Update[d].fTA;
NewMaster[w].fTM = Master[e].fTM + Update[d].fTM;
NewMaster[w].perTwo = ((Master[e].perTwo) + (Update[d].twoPTM / Update[d].twoPTA)*100) / 2;
NewMaster[w].perThree = ((Master[e].perThree) + (Update[d].threePTM / Update[d].threePTA)*100) / 2;
NewMaster[w].perFT = ((Master[e].perFT) + (Update[d].fTM / Update[d].fTA)) / 2;
NewMaster[w].fouls = Master[e].fouls + Update[d].fouls;
NewMaster[w].turnovers = Master[e].turnovers + Update[d].turnovers;
NewMaster[w].points = Master[e].points + Update[d].points;
w++;
e++;
}
else if (Update[d].action == "D")
{
e++;
}
}
if (Update[d].action == "A")
{
NewMaster[w].ID = Update[d].ID;
NewMaster[w].fName = Update[d].fName;
NewMaster[w].lName = Update[d].lName;
NewMaster[w].league = Update[d].league;
NewMaster[w].team = Update[d].team;
NewMaster[w].mins = Update[d].mins;
NewMaster[w].twoPTA = Update[d].twoPTA;
NewMaster[w].twoPTM = Update[d].twoPTM;
NewMaster[w].threePTA = Update[d].threePTA;
NewMaster[w].threePTM = Update[d].threePTM;
NewMaster[w].fTA = Update[d].fTA;
NewMaster[w].fTM = Update[d].fTM;
NewMaster[w].fouls = Update[d].fouls;
NewMaster[w].turnovers = Update[d].turnovers;
w++;
}
}
}
答案 0 :(得分:0)
在double ReadInRound(UpdateFile Up[], MasterFile Master[])
中,参数名为Up
,但您不断更新本地UpdateFile Update[500];
。
将其更改为Up
。