ok i have wrote this program and been trying to break into a class called football , but i keep getting an:

error error C2228: left of '.Season' must have class/struct/union

i have tried moving my stuct around in and out of the class but im not sure how to cure this problem any help and remmendations would be great

im going to leave my original code and my current code with header
football.h

#ifndef FOOTBALL_H
#define FOOTBALL_H


#include <iostream>
#include <fstream>
#include <string>
#include "Message.h"


using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};



class Football : public Message  
{ 
public:

	void WriteLastSearchWord(string word);
	void ReadLastSearchWord(string &team, int &record);
	void SearchMatches(Match* matches,int size,string TeamName);
	void SearchMatches(Match* matches,int size,string TeamName, int record);
	int  RunFootball();
	Football(string *footBallData);


	
	


	
protected:	
	
	string &footBallSave;
	string team;
	
	


};

#endif

football.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "Football.h"
#include "Message.h"


using namespace std;



//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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 counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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.txt
void 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.txt
void ReadLastSearchWord(string &team, int &record)
{
	ifstream inFile("nflSave.txt");
	getline(inFile, team);
	inFile >> record;
	inFile.close();
}



int 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;
		return 0;
	}

	// initalize the counter
	int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
		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 selection
	char 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 team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}

|
shadowfire36 May 15, 2008 at 12:33am
here is the original code

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};

// Display the main menu on screen
void DisplayMainMenu()
{
	cout<<"1- Please enter team name"<<endl;
	cout<<"2- View last record"<<endl;
	cout<<"3- Exit program"<<endl;
	cout<<"Please select number"<<endl;
}

//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(SearchResultCount>0)

	{
		
		
		cout << "which year would you like to view results "<<endl;
		cin>>SelectedNumber;

		SelectedNumber;
		
	ofstream myfile;
	myfile.open("recallTeam.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 counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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.txt
void WriteLastSearchWord(string word)
{
	ofstream myfile;
    myfile.open("recallTeam.txt");
    myfile <<word;
    myfile.close();
}
// This function is used for read the last search keyword enter from the recallteam.txt
void ReadLastSearchWord(string &team, int &record)
{
	ifstream inFile("recallTeam.txt");
	getline(inFile, team);
	inFile >> record;
	inFile.close();
}


int main()
{
	ifstream inFile("nfl.txt");
	//initailze the matches ( array of strcuts )
	Match matches[2000];

	// create input stream to nba.txt 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;
		return 0;
	}

	// initalize the counter
	int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
		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 selection
	char Check='1';

	while(Check !='3')
	{
		//Display the main menu
		DisplayMainMenu();
		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 team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}

On what line are you getting this error?

Please post you code between [code=cpp] //code here [/code] tags. That way line numbers will be added, which is handy with this amount of code ;)

ok i have updated this post now

error is on line 155-168 of the football.cpp
someone told me that my int Football::RunFootball() was out of scope but i wasnt sure what they meant

error C2228: left of '.Season' must have class/struct/union

and like i already said:

i have tried moving my stuct around in and out of the class but im not sure how to cure this problem any help and remmendations would be great

im going to leave my original code and my current code with header


football.h

#ifndef FOOTBALL_H
#define FOOTBALL_H


#include <iostream>
#include <fstream>
#include <string>
#include "Message.h"


using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};



class Football : public Message  
{ 
public:

	void WriteLastSearchWord(string word);
	void ReadLastSearchWord(string &team, int &record);
	void SearchMatches(Match* matches,int size,string TeamName);
	void SearchMatches(Match* matches,int size,string TeamName, int record);
	int  RunFootball();
	Football(string *footBallData);


	
	


	
protected:	
	
	string &footBallSave;
	string team;
	
	


};

#endif

football.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "Football.h"
#include "Message.h"


using namespace std;



//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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 counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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.txt
void 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.txt
void ReadLastSearchWord(string &team, int &record)
{
	ifstream inFile("nflSave.txt");
	getline(inFile, team);
	inFile >> record;
	inFile.close();
}



int 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;
		return 0;
	}

	// initalize the counter
	int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
		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 selection
	char 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 team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}

|
shadowfire36 May 15, 2008 at 12:33am
here is the original code

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};

// Display the main menu on screen
void DisplayMainMenu()
{
	cout<<"1- Please enter team name"<<endl;
	cout<<"2- View last record"<<endl;
	cout<<"3- Exit program"<<endl;
	cout<<"Please select number"<<endl;
}

//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(SearchResultCount>0)

	{
		
		
		cout << "which year would you like to view results "<<endl;
		cin>>SelectedNumber;

		SelectedNumber;
		
	ofstream myfile;
	myfile.open("recallTeam.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 counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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.txt
void WriteLastSearchWord(string word)
{
	ofstream myfile;
    myfile.open("recallTeam.txt");
    myfile <<word;
    myfile.close();
}
// This function is used for read the last search keyword enter from the recallteam.txt
void ReadLastSearchWord(string &team, int &record)
{
	ifstream inFile("recallTeam.txt");
	getline(inFile, team);
	inFile >> record;
	inFile.close();
}


int main()
{
	ifstream inFile("nfl.txt");
	//initailze the matches ( array of strcuts )
	Match matches[2000];

	// create input stream to nba.txt 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;
		return 0;
	}

	// initalize the counter
	int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
		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 selection
	char Check='1';

	while(Check !='3')
	{
		//Display the main menu
		DisplayMainMenu();
		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 team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}

Aha, that explains: (football.cpp line 133) Match* matches[2000]; is an array of pointers to match-structs.

Change it to Match matches[2000]; [edit] or what AD said

line 155: >> matches[matchesCounter].Season

matches is an array of unallocated pointers, so you have to use the pointer operator, like this: matches[matchesCounter]->Season Before you can do the above you have to allocate memory for the structures. Here's how:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		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++;
	}

you can simplify like this:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		getline(inFile,matches[matchesCounter]->Season);
		//read team1 name
		getline(inFile,matches[matchesCounter]->Team1);
		//read the "over" string
		getline(inFile,Buffer);
		//read team2 name
		getline(inFile,matches[matchesCounter]->Team2);
		//read result
		getline(inFile,matches[matchesCounter]->Result);
		//read the empty line
		getline(inFile,Buffer);
		//update the matches counter
		matchesCounter++;
	}

Small typo there Ancient: matches[matchesCounter] = new Matches; should be matches[matchesCounter] = new Match; But the OP gets the idea ;)

line 155: >> matches[matchesCounter].Season

matches is an array of unallocated pointers, so you have to use the pointer operator, like this: matches[matchesCounter]->Season Before you can do the above you have to allocate memory for the structures. Here's how:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		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++;
	}

you can simplify like this:

int matchesCounter=0;
	while(!inFile.eof())
	{
		//read season
                matches[matchesCounter] = new Matches; 
		getline(inFile,matches[matchesCounter]->Season);
		//read team1 name
		getline(inFile,matches[matchesCounter]->Team1);
		//read the "over" string
		getline(inFile,Buffer);
		//read team2 name
		getline(inFile,matches[matchesCounter]->Team2);
		//read result
		getline(inFile,matches[matchesCounter]->Result);
		//read the empty line
		getline(inFile,Buffer);
		//update the matches counter
		matchesCounter++;
	}

o wow Thanks you !!!

but i have one other issue im tying to use memory allocation
im trying to save the content of this funtion and call it some where else in my control call so that when a user presses 1 it will ready the content
im draw out a pusedo code :

football.h

string &footBallSave; 

void WriteLastSearchWord(string word);

void WriteLastSearchWord(string word)
{
ofstream myfile;
myfile.open("nflSave.txt");
myfile << word;
myfile << &footBallSave;
myfile.close();
}

now what i want to do is called

ok my the power to my computer shout down when i was at work so disregard that last post

here is my new code but im getting to error code i don't seem to understand what im doing wrong

error code

football.cpp(194) : error C2664: 'void Football::SearchMatches(Match *,int,std::string)' : cannot convert parameter 1 from 'Match *[2000]' to 'Match *'

football.cpp(205) : error C2664: 'void Football::SearchMatches(Match *,int,std::string,int)' : cannot convert parameter 1 from 'Match *[2000]' to 'Match *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

new football.h

#ifndef FOOTBALL_H
#define FOOTBALL_H


#include <iostream>
#include <fstream>
#include <string>
#include "Message.h"


using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};



class Football : public Message  
{ 
public:

	void WriteLastSearchWord(string word);
	void ReadLastSearchWord(string &team, int &record);
	void SearchMatches(Match *matches,int size,string TeamName);
	void SearchMatches(Match *matches,int size,string TeamName, int record);
	void  RunFootball();
	Football(string *footBallData);


	
	


	
protected:	
	
	string &footBallSave;
	string team;
	
	


};

#endif

new football.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "Football.h"
#include "Message.h"


using namespace std;



//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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 counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(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 results
	if(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.txt
void 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.txt
void 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 counter
	int 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 selection
	char 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 team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}
This article has been dead for over six months. Start a new discussion instead.