usaa20/cv6/main.c

108 lines
2.4 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"
2020-11-30 09:58:50 +00:00
#define MAX 1000
2020-11-29 18:02:03 +00:00
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){
2020-11-30 09:58:50 +00:00
FILE *fp = fopen("station.txt", "r");
if(fp == NULL){
printf("Nemozem najst stanice\n");
exit(1);
}
int i = 0;
while(1){
char s[30];
char *r = fgets(s, 30, fp);
s[strlen(s)-1] = '\0';
//printf("%s", car);
if(r == NULL){
if(feof(fp) != 0){
2020-11-30 13:17:02 +00:00
//printf("End of file\n");
2020-11-30 09:58:50 +00:00
break;
}
else{
printf("Error\n");
exit(0);
}
}
char pass[10];
if(!isdigit(s[i])){
fgets(pass, 10, fp);
pass[strlen(pass)-1] = '\0';
int num = atoi(pass);
add_target_capacity(station, s, num);
}
2020-11-29 18:02:03 +00:00
2020-11-30 09:58:50 +00:00
}
2020-11-30 13:17:02 +00:00
fclose(fp);
}
2020-11-29 18:02:03 +00:00
2020-11-30 14:11:06 +00:00
int main(){
2020-11-29 18:02:03 +00:00
struct station* station = create_station();
2020-11-30 13:50:00 +00:00
printf("Zadajte stanicu na pridanie do zoznamu:\n");
2020-11-30 14:11:06 +00:00
////////////////////////////
2020-11-30 13:50:00 +00:00
char add[30];
fgets(add, 30, stdin);
add[strlen(add)-1] = '\0';
printf("Zadajte capacitu stanice:\n");
2020-11-29 18:02:03 +00:00
2020-11-30 13:50:00 +00:00
char cap[10];
fgets(cap,10,stdin);
cap[strlen(cap)-1] = '\0';
int n = atoi(cap);
add_target_capacity(station,add,n);
2020-11-30 14:11:06 +00:00
/////////////////////////////
2020-11-30 13:50:00 +00:00
test_station(station);
2020-11-30 14:11:06 +00:00
int c_targets = count_targets(station);
printf("Aktualne existuju %d stanic\n", c_targets);
2020-11-30 13:50:00 +00:00
printf("\n");
print_station(station);
printf("\n");
2020-11-29 18:02:03 +00:00
printf("Zadajte hľadanu stanicu:\n");
2020-11-30 09:58:50 +00:00
char find[30];
fgets(find,30,stdin);
find[strlen(find)-1] = '\0';
2020-11-29 18:02:03 +00:00
printf("Výsledný vlak bude:\n");
2020-11-30 09:58:50 +00:00
int s = get_target_capacity(station, find);
2020-11-29 18:02:03 +00:00
print_station(station);
2020-11-30 09:58:50 +00:00
if(s == 0){
printf("Neexistuje taka stanica\n");
}
else{
printf("Capacita na danej statice: %d\n", s);
2020-11-30 13:50:00 +00:00
2020-11-30 09:58:50 +00:00
}
2020-11-30 13:50:00 +00:00
2020-11-29 18:02:03 +00:00
destroy_station(station);
return 0;
}