I am having trouble accessing my character arrays in my structure. I can read the data from a file without any problem. I can copy the numbers from the main variables into the structure w/o any problems, but when I try to access character arrays from the structure after having copied data into them I run into a problem.
Here is a sample of my code and output:
Code:
struct flight {
char[20] airline;
int num;
char[3] depart;
char[3] arrive;
char seat;
char meal;
};
struct flight flights[5];
int main(){
int a = 0; // counter
int b = 0; // counter
int fileCOUNT = 0;
char[20] airline; // airline name
int num = 0; // airline number
char[3] depart; // depart city
char[3] arrive; // arrive city
char seat; // seat preference
char meal; // meal preference
// open file and read in data
// first line is a number(fileCOUNT) specifying how many lines of data need to be read in
// for this case fileCOUNT = 1;
// copy data from main variables into flights structure array
// for airline, depart, and arrive I used same loop to copy data.
// **airline, depart, and arrive = example**
// (strlen(example) + 1) <- (+1) is to account for end of string character '\0'
for(a = 0; a < fileCOUNT; a++) {
for(b = 0; b < (strlen(example) + 1) {
flights[a].example[b] = example[b];
}
// copies data from airline, depart, and arrive into respective flights[a] variables
flights[a].num = num;
// copies num data into flights[a].num
}
//format and print out headers and data from both main and flights[a] structure
OUTPUT:
// exact output from my program
// data for main and flights[a] is printed out via a loop hence the a for the index in flights structure
Data from main:
Airline Number Depart Arrive Seat Meal // depart and arrive accessed via
American 232 DFW BNA a v // ..."%s %s", depart, arrive...
Data from flights[a]:
Airline Number Depart Arrive Seat Meal // depart and arrive accessed via
American 232 DFWBNAav BNAav a v // ..."%s %s", flights[a].depart, flights[a].arrive
As you can see I have some trouble either opying the character array data or accessing the character array data. Any help to solving this problem of mine would be much appreciated.
Thanks in advance for any help anyone can supply to me.