1
1
#include <stdio.h>
2
2
#include <stdlib.h>
3
3
#include <string.h>
4
+
4
5
struct flighttable {
5
6
int index ;
6
7
char source [25 ];
@@ -11,23 +12,24 @@ struct flighttable {
11
12
int minute ;
12
13
int price ;
13
14
};
14
- struct adjacency_matrix_struct { //[i][j] are gonna be city matrix indexes
15
+
16
+ struct adjacency_matrix_struct {
15
17
int adjacency ;
16
18
int hour ;
17
19
int minute ;
18
20
int price ;
19
21
};
22
+
20
23
void printflights (struct flighttable table [], int size );
21
24
void printadjmat (int city_count , struct adjacency_matrix_struct * * table );
25
+
22
26
int main () {
23
27
int i , j , k ;
24
28
int c1 , c2 ;
25
29
// user info variables
26
30
char user_source [25 ];
27
31
char user_destination [25 ];
28
32
int max_transfer ; // 0<transfer<city
29
- int max_duration ;
30
- int max_price ;
31
33
char selection_forextrainfo ;
32
34
char selection_tocontinue ;
33
35
char selection_duration ;
@@ -91,7 +93,7 @@ int main() {
91
93
if (i >= city_count ) {
92
94
city_count ++ ;
93
95
city_matrix [i ] = (char * )malloc (25 * sizeof (char ));
94
- * city_matrix = realloc (* city_matrix , city_count * sizeof (char * ));
96
+ city_matrix = realloc (city_matrix , city_count * sizeof (char * ));
95
97
sprintf (city_matrix [i ], flights [j ].source );
96
98
flights [j ].source_index = i ;
97
99
}
@@ -107,7 +109,7 @@ int main() {
107
109
if (i >= city_count ) {
108
110
city_count ++ ;
109
111
city_matrix [i ] = (char * )malloc (25 * sizeof (char ));
110
- * city_matrix = realloc (* city_matrix , city_count * sizeof (char * ));
112
+ city_matrix = realloc (city_matrix , city_count * sizeof (char * ));
111
113
sprintf (city_matrix [i ], flights [j ].destination );
112
114
flights [j ].destination_index = i ;
113
115
}
@@ -157,31 +159,27 @@ int main() {
157
159
printf ("\nPlease select your flight preferences." );
158
160
// a loop for user to make new selections here
159
161
printf ("\nWhere would you like to lift off from?\t" );
160
- scanf ("%s" , & user_source );
162
+ scanf ("%s" , user_source );
161
163
printf ("\nWhere would you like to land?\t" );
162
- scanf ("%s" , & user_destination );
164
+ scanf ("%s" , user_destination );
163
165
printf ("\nMaximum transfers you would like to allow:\t" );
164
166
scanf ("%d" , & max_transfer );
165
167
while (max_transfer > city_count ) {
166
168
printf ("\nThat is not allowed. Maximum allowed transfers are %d. Please pick again.\t" , city_count );
167
169
scanf ("%d" , & max_transfer );
168
170
}
169
171
printf ("\nWould you like to set additional constraints? y/n\t" );
170
- scanf ("%c" , & selection_forextrainfo );
171
- scanf ("%c" , & selection_forextrainfo );
172
+ scanf (" %c" , & selection_forextrainfo );
172
173
while ((selection_forextrainfo != 'y' ) && (selection_forextrainfo != 'n' )) {
173
174
printf ("\nThat is not allowed. Please select one of the two y/n:\t" );
174
- scanf ("%c" , & selection_forextrainfo );
175
- scanf ("%c" , & selection_forextrainfo );
175
+ scanf (" %c" , & selection_forextrainfo );
176
176
}
177
177
if (selection_forextrainfo == 'y' ) {
178
178
printf ("\nAdd a duration constraint? y/n\t" );
179
- scanf ("%c" , & selection_duration );
180
- scanf ("%c" , & selection_duration );
179
+ scanf (" %c" , & selection_duration );
181
180
while ((selection_duration != 'y' ) && (selection_duration != 'n' )) {
182
181
printf ("\nThat is not allowed. Please select one of the two y/n:\t" );
183
- scanf ("%c" , & selection_duration );
184
- scanf ("%c" , & selection_duration );
182
+ scanf (" %c" , & selection_duration );
185
183
}
186
184
if (selection_duration == 'y' ) {
187
185
printf ("How many hours?" );
@@ -191,12 +189,10 @@ int main() {
191
189
}
192
190
193
191
printf ("\nAdd a price constraint? y/n\t" );
194
- scanf ("%c" , & selection_price );
195
- scanf ("%c" , & selection_price );
192
+ scanf (" %c" , & selection_price );
196
193
while ((selection_price != 'y' ) && (selection_price != 'n' )) {
197
194
printf ("\nThat is not allowed. Please select one of the two y/n:\t" );
198
- scanf ("%c" , & selection_price );
199
- scanf ("%c" , & selection_price );
195
+ scanf (" %c" , & selection_price );
200
196
}
201
197
if (selection_price == 'y' ) {
202
198
printf ("Maximum price?" );
@@ -205,12 +201,10 @@ int main() {
205
201
}
206
202
207
203
printf ("\nProgram ended. Would you like to make new choices? y/n\t" );
208
- scanf ("%c" , & selection_tocontinue );
209
- scanf ("%c" , & selection_tocontinue );
204
+ scanf (" %c" , & selection_tocontinue );
210
205
while ((selection_tocontinue != 'y' ) && (selection_tocontinue != 'n' )) {
211
206
printf ("\nThat is not allowed. Please select one of the two y/n:\t" );
212
- scanf ("%c" , & selection_tocontinue );
213
- scanf ("%c" , & selection_tocontinue );
207
+ scanf (" %c" , & selection_tocontinue );
214
208
}
215
209
}
216
210
0 commit comments