main
This commit is contained in:
parent
c995ea81a7
commit
d0d15dad61
52
cv6/main.c
52
cv6/main.c
@ -5,6 +5,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "a_station.h"
|
#include "a_station.h"
|
||||||
|
|
||||||
|
#define MAX 1000
|
||||||
|
|
||||||
void print_station(struct station* station){
|
void print_station(struct station* station){
|
||||||
// Vypise celu stanicu
|
// Vypise celu stanicu
|
||||||
printf("station>>>\n");
|
printf("station>>>\n");
|
||||||
@ -23,19 +25,35 @@ void print_station(struct station* station){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_station(struct station* station){
|
void test_station(struct station* station){
|
||||||
|
FILE *fp = fopen("station.txt", "r");
|
||||||
|
if(fp == NULL){
|
||||||
|
printf("Nemozem najst stanice\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
while(1){
|
while(1){
|
||||||
char car[30];
|
|
||||||
fgets(car, 30, stdin);
|
char s[30];
|
||||||
car[strlen(car)-1] = '\0';
|
char *r = fgets(s, 30, fp);
|
||||||
if(car[0] == '\0'){
|
s[strlen(s)-1] = '\0';
|
||||||
|
//printf("%s", car);
|
||||||
|
|
||||||
|
if(r == NULL){
|
||||||
|
if(feof(fp) != 0){
|
||||||
|
printf("End of file\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char pass[30];
|
else{
|
||||||
if(!isdigit(car[0])){
|
printf("Error\n");
|
||||||
fgets(pass, 30, stdin);
|
exit(0);
|
||||||
pass[strlen(car)-1] = '\0';
|
}
|
||||||
|
}
|
||||||
|
char pass[10];
|
||||||
|
if(!isdigit(s[i])){
|
||||||
|
fgets(pass, 10, fp);
|
||||||
|
pass[strlen(pass)-1] = '\0';
|
||||||
int num = atoi(pass);
|
int num = atoi(pass);
|
||||||
add_target_capacity(station, car, num);
|
add_target_capacity(station, s, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,21 +62,23 @@ void test_station(struct station* station){
|
|||||||
|
|
||||||
int main(){
|
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();
|
struct station* station = create_station();
|
||||||
test_station(station);
|
test_station(station);
|
||||||
|
|
||||||
printf("Zadajte hľadanu stanicu:\n");
|
printf("Zadajte hľadanu stanicu:\n");
|
||||||
char clear[30];
|
char find[30];
|
||||||
fgets(clear,30,stdin);
|
fgets(find,30,stdin);
|
||||||
clear[strlen(clear)-1] = '\0';
|
find[strlen(find)-1] = '\0';
|
||||||
|
|
||||||
printf("Výsledný vlak bude:\n");
|
printf("Výsledný vlak bude:\n");
|
||||||
int s = get_target_capacity(station, clear);
|
int s = get_target_capacity(station, find);
|
||||||
print_station(station);
|
print_station(station);
|
||||||
|
if(s == 0){
|
||||||
|
printf("Neexistuje taka stanica\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
printf("Capacita na danej statice: %d\n", s);
|
printf("Capacita na danej statice: %d\n", s);
|
||||||
|
}
|
||||||
destroy_station(station);
|
destroy_station(station);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user