From a17788613644585c61758c0e73f9bfb8e7fc19ed Mon Sep 17 00:00:00 2001 From: Kozar Date: Fri, 8 Nov 2024 13:28:50 +0000 Subject: [PATCH] Initializacia --- cv6/a_station.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cv6/a_station.c b/cv6/a_station.c index f483f16..d104527 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -33,6 +33,23 @@ int select_track(struct station* station, const char* target){ } void add_target_capacity(struct station* station,const char* target, int capacity){ + int track = select_track(station, target); + struct car* current = station->tracks[track]; + + while (current) { + if (strcmp(current->value, target) == 0) { + current->capacity += capacity; + return; + } + current = current->next; + } + + struct car* new_car = malloc(sizeof(struct car)); + strncpy(new_car->value, target, TARGET_SIZE - 1); + new_car->value[TARGET_SIZE - 1] = '\0'; + new_car->capacity = capacity; + new_car->next = station->tracks[track]; + station->tracks[track] = new_car; } int get_target_capacity(struct station* station,const char* target){