usaa20/cv6/main.c

65 lines
1.5 KiB
C
Raw Normal View History

2020-11-29 18:02:03 +00:00
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "a_station.h"
void print_station(struct station* station){
// Vypise celu stanicu
printf("station>>>\n");
// Prechadza vsetky trate
for (int i = 0 ; i< station->track_count; i++){
struct car* start = station->tracks[i];
struct car* this = start;
// Prechadza vsetky vozne
while(this != NULL){
printf("%s %d -> ",this->value,this->capacity);
this=this->next;
}
printf("NULL\n");
}
printf("<<<station\n");
}
void test_station(struct station* station){
while(1){
char car[30];
fgets(car, 30, stdin);
car[strlen(car)-1] = '\0';
if(car[0] == '\0'){
break;
}
char pass[30];
if(!isdigit(car[0])){
fgets(pass, 30, stdin);
pass[strlen(car)-1] = '\0';
int num = atoi(pass);
add_target_capacity(station, car, num);
}
}
}
int main(){
printf("Zadajte zoznam cieľových staníc a počet cestujúcich.\n");
printf("Zoznam zakončite prázdnym riadkom.\n");
struct station* station = create_station();
test_station(station);
printf("Zadajte hľadanu stanicu:\n");
char clear[30];
fgets(clear,30,stdin);
clear[strlen(clear)-1] = '\0';
printf("Výsledný vlak bude:\n");
int s = get_target_capacity(station, clear);
print_station(station);
printf("Capacita na danej statice: %d\n", s);
destroy_station(station);
return 0;
}