2. Implement airport flight information data structure that contains the following data for the planes leaving on a given day: • Flight number • Originating airport (three characters) • Destination airport (three characters) • Departure time (four characters) If this definition must be visible to the main method and other methods, place it before the start of the main method – this makes it globally accessible. 3. Allocate at least five flight information structures on the heap and store appropriate data in them. The following statement allocates enough space for a single record and returns a pointer to it in the variable new_ptr, which must be declared to be a pointer to the structure type described above. /* Allocate space on heap for one structure, assign pointer to new_ptr */ struct flight_info * new_ptr = (struct flight_info *)malloc(sizeof(struct flight_info)); /* Put data in structure */ new_ptr->flightNumber = 125; (void)strcpy((* new_ptr).origAirport, "CHS"); /* copy a string */ (void)strcpy (new_ptr->destAirport, "CLT"); (void)strcpy (new_ptr-> departureTime, "1000"); In addition to <stdio.h>, include <stdlib.h> and <string.h> for malloc and strcpy.
Here is what I have:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct flightInfo {
int flightNum;
char departAirport[3];
char destAirport[3];
char departTime[4];
}
main() {
/* Allocate space on heap for one structure. Then assign pointer to new_ptr. */
struct flightInfo * new_ptr = (struct flightInfo *)malloc(sizeof(struct flightInfo));
/* Put data in structure. */
new_ptr -> flightNum = 125;
(void)strcpy ((* new_ptr).departAirport, "CHS"); /* copy a string */
(void)strcpy (new_ptr-> destAirport, "CLT");
(void)strcpy (new_ptr-> departTime, "1000");
}
Here is my error:
Exited: ExitFailure 120
I need help with the error. I can't seem to find any help with google.
I have 2 other questions!
- Is the memory being allocated for the struct actually being done on the heap?
- What editor do you use for C programming? My teacher has me on codepad.org doing this assignment.

New Topic/Question
Reply




MultiQuote









|