No se que problema puede existir pero no obtengo el resultado deseado:
Código:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Exercise 12-4: Write a program that lists all the planes that leave from two
//airports specified by the user.
int main(void)
{
int i;
char city1[2], city2[2]; // airports specified by the user
struct airline {
int flight_N; // Flight number
char origin_airp[]; // Originating airport code (three characters)
char desti_airp[]; //Destination airport code (three characters)
int start_time[]; //Starting time
int arrive_time[]; //Arrival time
};
struct airline myfli[4];
myfli[0].flight_N = 329;
strcpy(myfli[0].origin_airp,"ABC");
strcpy(myfli[0].desti_airp,"KID");
myfli[0].start_time[0] = 05;
myfli[0].start_time[1] = 30;
myfli[0].arrive_time[0] = 10;
myfli[0].arrive_time[1] = 55;
myfli[1].flight_N = 323;
strcpy(myfli[1].origin_airp,"CCC");
strcpy(myfli[1].desti_airp,"LLI");
myfli[1].start_time[0] = 05;
myfli[1].start_time[1] = 30;
myfli[1].arrive_time[0] = 9;
myfli[1].arrive_time[1] = 55;
myfli[2].flight_N = 559;
strcpy(myfli[2].origin_airp,"BBB");
strcpy(myfli[2].desti_airp,"AAA");
myfli[2].start_time[0] = 07;
myfli[2].start_time[1] = 30;
myfli[2].arrive_time[0] = 10;
myfli[2].arrive_time[1] = 55;
strcpy(city1,"ABC");
strcpy(city2,"CCC");
for (i = 0; i < 4; ++i) {
if (strcmp(myfli[i].origin_airp, city1) == 0 || strcmp(myfli[i].origin_airp, city2) == 0 ){
printf("Plane Numer: %d\n", myfli[i].flight_N); }
}
return (0);
}
En el ultimo for y if intento rastear todos los registros de la estructura buscando si coinciden las cadenas city1 y city2 para imprimirlas, pero el resulado impreso no tiene nada que ver con los datos que tenemos
Gracias y saludos!