Hello! I want to pass array of struct to a function. After from that function to pass it to another function.

I made some efforts but without result.

Those are some parts of my code

i create the structure to my main function

airplane ticket[numberOfTickets];

from main function i pass parameters to showMenu function.Until here all are ok

showMenu(ticket,numberOfTickets);

and from showMenu function i pass parameters to bookSeatAssignment function, but something i do wrong here

bookSeatAssignment(showMenuTickets,showMenuNumberOfTickets);

Thanks!

In the parameter list for your function prototypes and definition you need to declare the parameter as accepting an array of that struct type. Example:

void showMenu(airplane arr[], int numberOfTickets);

When passing arguments to that function, only pass the name of the instance of your airplane struct. Example:

showMenu(tickets, numOfTickets);

yeah, but after i want to send the parameters to another function

My best guess without seeing the showMenu function is that showMenuTickets isn't assigned correctly to ticket.

I'm seeing quite a few issues in the code ... How many errors do you get when you compile?

void createTickets(char ticket[20],bool modified,char name[40]);

This is wrong. If you want to pass the size of the arrays, you will need a seperate int value.

void createTickets(char ticket[],bool modified,char name[], int ticketLen, int nameLen);

But since this is a class function declaration, it can be written as

void createTickets(char[], bool, char[], int, int);

The actual function header should be

void airplane::createTickets(char ticket[],bool modified,char name[], int ticketLen, int nameLen)
{

I'm not sure what types of errors the above will give doing it the way you have it, or even if it is giving errors at all since I don't have a compiler, but the way it is now doesn't look right.

Now, looking at your bookSeatAssignment

void bookSeatAssignment(airplane bookTickets[],int numberOfTickets)
{
		string seatId;
		string seatHolder;

		bool emptySeat;
		emptySeat=false;

			cout<<"Enter name of holder: "<<endl;
			getline(cin,seatHolder);

			cout<<"Enter seat id: "<<endl;
			getline(cin,seatId);
			
			cout<<endl;
			//cout<<"name of holder: "<<seatHolder;

	/*	for (i=0;i<=11;i++)
		{
			bookSeatsTickets[i].countEmptySeats();
		}

		if (totalEmptySeats==0)
			cout<<"You can`t make reservation. There is no empty seat right now"<<endl;
		if (totalEmptySeats>0)
		{*/
			//seatId="B3";
			//seatHolder="Alex Papasavva";
			//cout<<seatId<<endl;
			//convertSeat(bookTickets,seatId,seatHolder);
		//}

}

Most of it is commented out, but looking at what you have commented out, what is:
bookSeatsTickets.countEmptySeats();

bookSeatsTickets is an undefined variable.

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.