Skip to content

Commit 81e7cdc

Browse files
debug
1 parent 88b0bc4 commit 81e7cdc

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

flight_graph/flight_graph.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <string.h>
4+
45
struct flighttable {
56
int index;
67
char source[25];
@@ -11,23 +12,24 @@ struct flighttable {
1112
int minute;
1213
int price;
1314
};
14-
struct adjacency_matrix_struct { //[i][j] are gonna be city matrix indexes
15+
16+
struct adjacency_matrix_struct {
1517
int adjacency;
1618
int hour;
1719
int minute;
1820
int price;
1921
};
22+
2023
void printflights(struct flighttable table[], int size);
2124
void printadjmat(int city_count, struct adjacency_matrix_struct **table);
25+
2226
int main() {
2327
int i, j, k;
2428
int c1, c2;
2529
// user info variables
2630
char user_source[25];
2731
char user_destination[25];
2832
int max_transfer; // 0<transfer<city
29-
int max_duration;
30-
int max_price;
3133
char selection_forextrainfo;
3234
char selection_tocontinue;
3335
char selection_duration;
@@ -91,7 +93,7 @@ int main() {
9193
if (i >= city_count) {
9294
city_count++;
9395
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 *));
9597
sprintf(city_matrix[i], flights[j].source);
9698
flights[j].source_index = i;
9799
}
@@ -107,7 +109,7 @@ int main() {
107109
if (i >= city_count) {
108110
city_count++;
109111
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 *));
111113
sprintf(city_matrix[i], flights[j].destination);
112114
flights[j].destination_index = i;
113115
}
@@ -157,31 +159,27 @@ int main() {
157159
printf("\nPlease select your flight preferences.");
158160
// a loop for user to make new selections here
159161
printf("\nWhere would you like to lift off from?\t");
160-
scanf("%s", &user_source);
162+
scanf("%s", user_source);
161163
printf("\nWhere would you like to land?\t");
162-
scanf("%s", &user_destination);
164+
scanf("%s", user_destination);
163165
printf("\nMaximum transfers you would like to allow:\t");
164166
scanf("%d", &max_transfer);
165167
while (max_transfer > city_count) {
166168
printf("\nThat is not allowed. Maximum allowed transfers are %d. Please pick again.\t", city_count);
167169
scanf("%d", &max_transfer);
168170
}
169171
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);
172173
while ((selection_forextrainfo != 'y') && (selection_forextrainfo != 'n')) {
173174
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);
176176
}
177177
if (selection_forextrainfo == 'y') {
178178
printf("\nAdd a duration constraint? y/n\t");
179-
scanf("%c", &selection_duration);
180-
scanf("%c", &selection_duration);
179+
scanf(" %c", &selection_duration);
181180
while ((selection_duration != 'y') && (selection_duration != 'n')) {
182181
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);
185183
}
186184
if (selection_duration == 'y') {
187185
printf("How many hours?");
@@ -191,12 +189,10 @@ int main() {
191189
}
192190

193191
printf("\nAdd a price constraint? y/n\t");
194-
scanf("%c", &selection_price);
195-
scanf("%c", &selection_price);
192+
scanf(" %c", &selection_price);
196193
while ((selection_price != 'y') && (selection_price != 'n')) {
197194
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);
200196
}
201197
if (selection_price == 'y') {
202198
printf("Maximum price?");
@@ -205,12 +201,10 @@ int main() {
205201
}
206202

207203
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);
210205
while ((selection_tocontinue != 'y') && (selection_tocontinue != 'n')) {
211206
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);
214208
}
215209
}
216210

0 commit comments

Comments
 (0)