#include<iostream.h>
/* structure*/
struct Reservation //defining the structure
{
char pName[20];
char pAdress[30];
int flight_date;
char destination[20];
int flight_no;
int seat_no;
};
/*Function*/
void GetData(Reservation rs, int size_of_reservation);
/*Main Function*/
void main ()
{
int size_of_reservation;
cout<<"Enter the number of reservation:";
cin>>size_of_reservation;
Reservation *rs = new Reservation[size_of_reservation];
GetData(*rs,size_of_reservation);
}
/* Function Will Get User Data */
void GetData(Reservation *rs, int size_of_reservation)
{
for(int i=0; i<=size_of_reservation; i++)
{
cout<<"Please Enter Passenger Name. ";
cin>>rs[i].pName;
}
}
how I can access struct array in any other function
Pass it as an argument just like you did to GetData.
I'm not sure I understand your question. You have already done this.
Can you clarify your question? What is it you're trying to do, or don't understand?
If you want *rs to be available to any function, you can make *rs global, but that is a practice that should be avoided.
Usually, the simplest way to get the definition and prototype declaration to match is to copy&paste.
In this case copy line 33 and paste it just above line 16:
15 16 17
/*Function*/
void GetData(Reservation *rs, int size_of_reservation) // was line 33
void GetData(Reservation rs, int size_of_reservation); // old line 16
See the difference now?
Next add a semicolon to the end of the new line 16 and delete the old one.
One more thing. Change <= to < in the for loop at line 35.