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


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



7 Years
Discussion Span
Last Post by kes166

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);

Edited by hag++: n/a


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;

			cout<<"Enter name of holder: "<<endl;

			cout<<"Enter seat id: "<<endl;
			//cout<<"name of holder: "<<seatHolder;

	/*	for (i=0;i<=11;i++)

		if (totalEmptySeats==0)
			cout<<"You can`t make reservation. There is no empty seat right now"<<endl;
		if (totalEmptySeats>0)
			//seatHolder="Alex Papasavva";


Most of it is commented out, but looking at what you have commented out, what is:

bookSeatsTickets is an undefined variable.

Edited by kes166: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.