#include <iostream>#include <fstream>#include <string>#include "Football.h"#include "Message.h"usingnamespace std;
//Search within array of matches and display the resultsvoid SearchMatches(Match* matches,int size,string TeamName)
{
//declare the result array
Match SearchResult[2000];
//initalize the result counterint SearchResultCount=0;
int SelectedNumber;
//search within the matches arrayfor(int i=0;i<size;i++)
{
//check if the entered name is the team1 or team2 in the matchif(matches[i].Team1==TeamName || matches[i].Team2==TeamName)
{
//update the search result counter
SearchResultCount++;
//display the seasons
cout<<endl<<"("<<SearchResultCount<<") "<<matches[i].Season;
//store the matched match in the search result array
SearchResult[SearchResultCount] = matches[i];
}
}
cout << endl;
//check for resultsif(SearchResultCount>0)
{
cout << "which year would you like to view results "<<endl;
cin>>SelectedNumber;
SelectedNumber;
ofstream myfile;
myfile.open("nflSave.txt",ios::app);
myfile << endl << SelectedNumber;
myfile.close();
//display the match information
cout<<SearchResult[SelectedNumber].Season<<endl;
cout<<SearchResult[SelectedNumber].Team1<<endl;
cout<<"Over"<<endl;
cout<<SearchResult[SelectedNumber].Team2<<endl;
cout<<SearchResult[SelectedNumber].Result<<endl;
}
else cout<<"No search result";
cout<<endl;
}
void SearchMatches(Match* matches,int size,string TeamName, int record)
{
//declare the result array
Match SearchResult;
//initalize the result counterint SearchResultCount=0;
//int SelectedNumber;//search within the matches arrayfor(int i=0;i<size;i++)
{
//check if the entered name is the team1 or team2 in the matchif(matches[i].Team1==TeamName || matches[i].Team2==TeamName)
{
//update the search result counter
SearchResultCount++;
if (SearchResultCount == record)
{
//store the //display the seasons//cout<<endl<<"("<<SearchResultCount<<") "<<matches[i].Season;//store the matched match in the search result array
SearchResult = matches[i];
break;
}
}
}
cout<<endl;
//check for resultsif(SearchResultCount>0)
{
//display the match information
cout<<SearchResult.Season<<endl;
cout<<SearchResult.Team1<<endl;
cout<<"Over"<<endl;
cout<<SearchResult.Team2<<endl;
cout<<SearchResult.Result<<endl;
}
else cout<<"No search result";
cout<<endl;
}
// This function is used for storing the last search keyword entered to the recallteam.txtvoid WriteLastSearchWord(string word)
{
ofstream myfile;
myfile.open("nflSave.txt");
myfile << word;
myfile.close();
}
// This function is used for read the last search keyword enter from the recallteam.txtvoid ReadLastSearchWord(string &team, int &record)
{
ifstream inFile("nflSave.txt");
getline(inFile, team);
inFile >> record;
inFile.close();
}
void Football::RunFootball()
{
ifstream inFile("nfl.txt");
//initailze the matches ( array of strcuts )
Match *matches[2000];
// create input stream for file//It will holds the read lines from the file
string Buffer;
// check if the file is exist if(!inFile.is_open())
{
//display the error message//cout<<"Failed to open file"<<endl;
cerr << " File is Missing";
}
// initalize the counterint matchesCounter=0;
while(!inFile.eof())
{ //&Match::operator =(const Match &)//read season
matches[matchesCounter] = new Match;
getline(inFile,Buffer);
matches[matchesCounter]->Season = Buffer;
//read team1 name
getline(inFile,Buffer);
matches[matchesCounter]->Team1 = Buffer;
//read the "over" string
getline(inFile,Buffer);
//read team2 name
getline(inFile,Buffer);
matches[matchesCounter]->Team2 = Buffer;
//read result
getline(inFile,Buffer);
matches[matchesCounter]->Result = Buffer;
//read the empty line
getline(inFile,Buffer);
//update the matches counter
matchesCounter++;
}
//its used for Main menu selectionchar Check='1';
while(Check !='3')
{
//Display the main menu
cin>>Check;
switch(Check)
{
//Search case'1':
{
string TeamName="";
getline(cin,TeamName);
system("cls");
cout << "Please Enter Team City And Team Name" <<endl;
getline(cin,TeamName);//free's buffer
WriteLastSearchWord(TeamName);
SearchMatches(matches,matchesCounter,TeamName);
break;
}
//Display the last search teamcase'2':
{
string team;
int record;
ReadLastSearchWord(team, record);
system("cls");
cout << "Last Recorded Viewed" <<endl;
SearchMatches(matches,matchesCounter ,team , record);
break;
}
//Exit the programcase'3':
{
exit(0);
}
default:continue;
}
}
}
I belive the problem is that you have the declaration
1 2
//initailze the matches ( array of strcuts )
Match *matches[2000];
which declares an array of pointers to Match, but the function is expecting a pointer to Match (not an array of pointers). You would need void SearchMatches(Match* matches[],int size,string TeamName, int record) to make the two compatible. Which would mean other changes in SearchMatches...
If in SearchMatches matches is an array of pointers then SearchResult will also need to be a pointer OR you will need to dereference matches[i] in order to make
SearchResult = matches[i]; work.