-
Notifications
You must be signed in to change notification settings - Fork 2
/
airport.c
77 lines (53 loc) · 1.56 KB
/
airport.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include "airport.h"
int airport_counter(FILE *fptr)
{
int numberOfAirport=1;
char c;
for (c = getc(fptr); c != EOF; c = getc(fptr))
{
if (c == '\n') // Increment count if this character is newline
numberOfAirport = numberOfAirport + 1;
}
rewind(fptr);
return numberOfAirport;
}
void fill_list_of_airports(FILE *fptr, struct airport **airports,int numberOfAirport)
{
struct airport* airport;
airport =&(*airports);
int counter=0;
char IATA [4];
char city[15];
char country[15];
while(!feof(fptr))
{
fscanf(fptr,"%4s",IATA);
fscanf(fptr,"%15s",city);
fscanf(fptr,"%15s",country);
airport[counter].airportId=counter;
strcpy(airport[counter].IATA,IATA);
strcpy(airport[counter].city,city);
strcpy(airport[counter].country,country);
counter++;
}
fclose(fptr);
}
void list_All_Airports(struct airport *airports,int numberOfAirport)
{
for(int i=0;i<numberOfAirport;i++)
{
printf("airport id:%d\t%5s\t%15s %15s \n",airports[i].airportId,airports[i].IATA,airports[i].city,airports[i].country);
}
}
int airport_mapper(char IATA[4],struct airport** headOfArray)
{
struct airport *airports;
airports=&(*headOfArray);
int x =0;
while(strcmp(IATA,airports[x].IATA)!=0)
{
x++;
}
return x;
}