Dear all
I have the following code

void initializeData()
{
	Customers *CustArray;
	CustArray=new Customers[150];//allocate 150 memory locations of class Customers  
	Flights *FL=new Flights[150];
	}
/*End Initialize Data fuction*/
/**********************************************************************************************************************************/
/*Backup Menu implementation*/

void backupfiledefaultfilename()
{	    

	ofstream file_ptr; // Declares a file pointer.
	file_ptr.open(“backup.bak”, ios::out); 
	if (!file_ptr)
	    { cout << “Error opening file.\n”; }
	    else
	    {
	    // Rest of output commands go here.
			for (int c=0; c>150; c++) 
			{
			file_ptr.write(&CustArray[c], sizeof(Customers));
			}
			for (int n=0; n>150; n++) 
			{
			file_ptr.write(&FL[n], sizeof(Flights));
			}
	}
}

gives me an arror on these lines
file_ptr.open(“backup.bak”, ios::out);
file_ptr.write(&CustArray[c], sizeof(Customers));
file_ptr.write(&FL[n], sizeof(Flights));

What to do?

Dear all
I have the following code

void initializeData()
{
	Customers *CustArray;
	CustArray=new Customers[150];//allocate 150 memory locations of class Customers  
	CustArray[0].addCustomers(1,801423,"Lefteris Zacharia", "Saint Gregoriou 1", 99669805, 2);
	CustArray[1].addCustomers(2,801723,"Zacharias Zachariou", "Ithakis 3", 99617525, 1);
	CustArray[2].addCustomers(3,901723,"Eleni Zachariou", "Ithakis 3", 99617525, 1);
	CustArray[3].addCustomers(4,1001723,"Demetriana Zachariou", "Ithakis 3", 99617525, 1);
	CustArray[4].addCustomers(5,111723,"Geroge Zachariou Aresti", "Saint Gregoriou 1", 99617525, 1);
	CustArray[5].addCustomers(6,901723,"Christina Zachariou", "Ithakis 8", 99617525, 1);
	CustArray[6].addCustomers(7,801223,"Antri Zachariou", "Ithakis 3", 99617525, 1);
	CustArray[7].addCustomers(8,901113,"Marios Charalambous", "Ithakis 8", 99617525, 1);
	Flights *FL=new Flights[150];
	FL[0].addFlights("CY326", "Larnaca" ,"London", 326, 27122010);
	FL[1].addFlights("CY327", "London" ,"Larnaca", 315, 28122010);
	FL[2].addFlights("BA625", "London" ,"Larnaca", 615, 27122010);
	FL[3].addFlights("BA625", "Larnaca" ,"London", 615, 28122010);
	FL[4].addFlights("OA325", "Athens" ,"Cairo", 310, 29122010);
	FL[5].addFlights("OA326", "Cairo" ,"Athens", 315, 30122010);
	}
/*End Initialize Data fuction*/
/**********************************************************************************************************************************/
/*Backup Menu implementation*/

void backupfiledefaultfilename()
{	    

	ofstream file_ptr; // Declares a file pointer.
	file_ptr.open(“backup.bak”, ios::out); 
	if (!file_ptr)
	    { cout << “Error opening file.\n”; }
	    else
	    {
	    // Rest of output commands go here.
			for (int c=0; c>150; c++) 
			{
			file_ptr.write(&CustArray[c], sizeof(Customers));
			}
			for (int n=0; n>150; n++) 
			{
			file_ptr.write(&FL[n], sizeof(Flights));
			}
	}
}

gives me an arror on these lines
file_ptr.open(“backup.bak”, ios::out);
file_ptr.write(&CustArray[c], sizeof(Customers));
file_ptr.write(&FL[n], sizeof(Flights));

What to do?

Ficed the error on the first line.
Now the problem on the following line its becasue its a function? and these are not see outside the function?
how I am going to declare globally a declaration inside a fuction?

What is the error message?

What is the error message?

These are the errors below:

1>------ Build started: Project: Backup, Configuration: Debug Win32 ------
1> Backup.cpp
1>c:\users\lefteris\documents\visual studio 2010\projects\lefteris_u104n0368\backup\backup\backup.cpp(227): error C2065: 'CustArray' : undeclared identifier
1>c:\users\lefteris\documents\visual studio 2010\projects\lefteris_u104n0368\backup\backup\backup.cpp(231): error C2065: 'FL' : undeclared identifier
1>c:\users\lefteris\documents\visual studio 2010\projects\lefteris_u104n0368\backup\backup\backup.cpp(250): error C2065: 'CustArray' : undeclared identifier
1>c:\users\lefteris\documents\visual studio 2010\projects\lefteris_u104n0368\backup\backup\backup.cpp(254): error C2065: 'FL' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

'CustArray' is declared in initializeData(). Therefore 'custArray' is local to initializeData(). 'custArray' is unavailable in backupfiledefaultfilename().

You want to make 'CustArray' global to use in backupfiledefaultfilename().

Or you could pass custArray into the backupfiledefaultfilename() as a parameter.

commented: Exactly +16

Can you please give me an example how to use them globally?
I have them in my main because i want them to be initalized after the user log in into the program..

I am really stuct in this

Please send your full code.

May I ask something before postng my code.
The functions backupfiledefaultfilename() etc we are discussing here should be member functions of the class Customers???

I have edited a little bit my code :

SO I have a switch statement in a function:I have made the initialiazation here and in another switch statement beccause the initiallization is local.

/*Data Initialization to Customers and Flights*/
	Customers *CustArray;
	CustArray=new Customers[150];//allocate 150 memory locations of class Customers  
	CustArray[0].addCustomers(1,8081423,"Lefteris", "Saint 1", 99888, 2);
int mochoice = 0;
int si;//
bool MOValid = false; // used for main menu
while (MOValid == false) 
{
	displayline();
	cout << "Airport Management System-Menu Options\n\n";
	displayline();
	cout<< "1.Insert flights\n";
	cout << "2.Customer details\n";
	cout << "3.Kind of membership\n";
	cout << "4.Flight Code Details\n";
	cout << "5.Select Meal\n";
	cout << "6.Select Drinks\n";
	cout << "7.Select Seat\n";
	cout << "8.Return back\n";

	//user choice
	cin >> mochoice;

if ((mochoice<1)&&(mochoice>8))//if not in the range of the choices
{
	cout << "Please make your selection, chose a digit from 1-8"<<endl;
}
else
MOValid = true;
}//end while	

	// choice of the user
	switch (mochoice)
{
	case '1':
	//addflights();
	break;
    case 2:
    cout<<"Please enter Systems Customer ID"<<endl;
    cin>>si;
	for (int i=0; i<ncustomers_in_system;i++)
    {
	if (si==CustArray[i].id) //TO DO globally declare
	{
	CustArray[i].showCustomers(); //TO DO same declaration here
	}
	}
    break;
	//membershiptype();
	break;
	case '4':
	//flightcodedetails();
	break;
	case '5':
	//meal();
	break;
	case '6':
	void drinks();
	break;
	case '7':
	//seat();
	break;
	case '8':
	int menu();
	break;
	default:
	system("cls");
	cout<<"Invalid selection. Please try again.\n\n\n"<<endl;
	menuoptions();
}//end switch
}//end menuoptions function
/*End Menu options implementation*/

Eg: for global declaration

Customers *CustArray;  // global declaration

void initializeData()
{
 CustArray=new Customers[150];
 Flights *FL=new Flights[150];
}

// Rest of code

Try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.