hello!
i'm trying to implement a function which build struct by adding each struct at a certain postion which been set by "number of flight"
the struct build like this:
Code:
typedef struct flight_{
int number;
char* date;
char* origin;
char* destination;
struct passengerslist* passengers;
}flight;
typedef struct flightslist{
flight* info;
struct flightslist* next;
}flights_list;
the prototype of this function is the following:
flights_list* add_flight(flights_list* flights, int number,char* date, char*
origin, char* destination)
i got trouble when i'm trying to copy the strings such date, origin and so
to certain struct.
i use strcpy.
this is my code.
Code:
flights_list* add_flight(flights_list* flights, int number,char* date, char* origin, char* destination){
flights_list *temp, *newCell, *head;
flight *temp_info;
temp_info=(flight*)malloc(sizeof(flight));
newCell=(flights_list*)malloc(sizeof(flights_list));
strcpy(temp_info->date,date);
strcpy(temp_info->destination,destination);
strcpy(temp_info->origin,origin);
temp_info->number=number;
newCell->info=temp_info;
if(flights==NULL){
newCell->next=flights;
return newCell;
}
head=flights;
while(head != NULL || newCell->info->number > head->info->number){
temp=head;
newCell->next=head;
temp->next=newCell;
head=head->next;
}
head=temp;
return head;
}