Initializacia
This commit is contained in:
parent
57490613d2
commit
cc577a088c
BIN
cv6/a_station.o
BIN
cv6/a_station.o
Binary file not shown.
77
cv6/main.c
77
cv6/main.c
@ -1,41 +1,54 @@
|
|||||||
#include "a_station.h"
|
#include "a_station.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void print_station(struct station* station){
|
#define MAX_INPUT 100
|
||||||
// Vypise celu stanicu
|
|
||||||
printf("station>>>\n");
|
void test_station(struct station* station) {
|
||||||
// Prechadza vsetky trate
|
char station_name[MAX_INPUT];
|
||||||
for (int i = 0 ; i< station->track_count; i++){
|
int capacity;
|
||||||
struct car* start = station->tracks[i];
|
|
||||||
struct car* this = start;
|
printf("Enter station name and capacity (or 'exit' to stop):\n");
|
||||||
// Prechadza vsetky vozne
|
|
||||||
while(this != NULL){
|
while (1) {
|
||||||
printf("%s %d -> ",this->value,this->capacity);
|
printf("Station name: ");
|
||||||
this=this->next;
|
if (!fgets(station_name, MAX_INPUT, stdin)) break;
|
||||||
|
|
||||||
|
// Remove trailing newline
|
||||||
|
station_name[strcspn(station_name, "\n")] = '\0';
|
||||||
|
|
||||||
|
if (strcmp(station_name, "exit") == 0) break;
|
||||||
|
|
||||||
|
printf("Capacity: ");
|
||||||
|
if (scanf("%d", &capacity) != 1) {
|
||||||
|
printf("Invalid input. Try again.\n");
|
||||||
|
while (getchar() != '\n'); // Clear input buffer
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
printf("NULL\n");
|
|
||||||
|
// Clear input buffer
|
||||||
|
while (getchar() != '\n');
|
||||||
|
|
||||||
|
add_target_capacity(station, station_name, capacity);
|
||||||
|
|
||||||
|
int track = select_track(station, station_name);
|
||||||
|
printf("Track for %s: %d\n", station_name, track);
|
||||||
|
|
||||||
|
int current_capacity = get_target_capacity(station, station_name);
|
||||||
|
printf("Current capacity to %s: %d\n\n", station_name, current_capacity);
|
||||||
}
|
}
|
||||||
printf("<<<station\n");
|
|
||||||
}
|
printf("Final Statistics:\n");
|
||||||
// Pre overenie ci to ide v poriadku
|
printf("Total number of targets: %d\n", count_targets(station));
|
||||||
void test_station(struct station* station){
|
printf("Total capacity: %d\n", count_capacity(station));
|
||||||
const char* stations[] = {"Presov","Kosice","Banska Bystrica","Banska Stiavnica","Povazska Bystrica","Snina","Humenne","Bratislava","Pezinok","Skalica","Ruzomberok","Bidovce","Michalovce","Poprad","Krompachy","Smizany","Vajkovce","Budimir","Modra","Myslava","Roznava","Gemerska Poloma","Stratena","Dobsina","Michalany","Kostolany"};
|
|
||||||
int size=26;
|
|
||||||
for (int i = 0; i < 50; i++){
|
|
||||||
int s = rand() % size;
|
|
||||||
int c = rand() % 20;
|
|
||||||
printf("%s %d\n",stations[s],c);
|
|
||||||
add_target_capacity(station,stations[s],c);
|
|
||||||
print_station(station);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main() {
|
||||||
srand(time(NULL));
|
struct station* station = create_station();
|
||||||
struct station* station = create_station();
|
test_station(station);
|
||||||
test_station(station);
|
destroy_station(station);
|
||||||
destroy_station(station);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
cv6/main.o
BIN
cv6/main.o
Binary file not shown.
BIN
cv6/station
BIN
cv6/station
Binary file not shown.
Loading…
Reference in New Issue
Block a user