2015-04-15 18 views
0

当我将它从函数中传递出来时,我的数组被视为一个变量。我已经尝试了多个修复程序,但似乎没有任何工作。在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

你真的应该使用'std :: vector'或'std :: array'来代替裸数组。 –

+0

所有数组*都是*变量。 – chris

+0

我应该包括结构。基本上,发生的事情是从我的调试器中填充为数组变成变量。 –

回答

0

double ReadInRound(UpdateFile Up[], MasterFile Master[])参数被命名为Up,但是你继续更新本地UpdateFile Update[500];

将它们更改为Up

+0

我做过了,我评论了一下。它应该接近ReadInRound中while循环的末尾。 –

+0

@EricJesse NO,不能以这种方式分配数组。如果'UpdateFile'的赋值操作符被正确定义,则可以按元素分配。 – timrau

+0

假设我保留它作为更新并将其作为一个参数(当我没有它本地,并保持它在主要它会使它成为一个变量,而不是一个数组),这可能会解决我的问题? –

相关问题