c++ - Array Getting Treated Like a Variable in Another Function -
my array being treated variable when pass out of function. have tried multiple fixes , none have seemed work. in readinround function file writes out file i'm reading in. bring update[] array append function can append file i'm writing to.
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 open.\n"; } return x;} void append(double& roundcount, masterfile master[], updatefile update[], int& x, masterfile newmaster[]){ int w = 0; (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++; } } }
in double readinround(updatefile up[], masterfile master[])
parameter named up
, keep updating local updatefile update[500];
.
change them up
.
Comments
Post a Comment