From 39b29d313106c4f899482390db10993ca812605b Mon Sep 17 00:00:00 2001 From: Anton Dolozin Date: Wed, 5 Nov 2025 11:28:52 +0100 Subject: [PATCH] Fixing adding --- du5/a_station.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/du5/a_station.c b/du5/a_station.c index 7c62bf4..4727626 100644 --- a/du5/a_station.c +++ b/du5/a_station.c @@ -58,42 +58,37 @@ void add_target_capacity(struct station* station,const char* target, int capacit int get_target_capacity(struct station* station,const char* target){ - struct car* ptr = *station->tracks; - while (ptr) - { if(strcmp(ptr->value, target) == 0){ - return ptr->capacity; - - } - ptr = ptr->next; - - + int res = select_track(station, target); + struct car** ptr = &station->tracks[res]; + struct car* head = *ptr; + if(head){ + return head->capacity; } + return 0; } int count_targets(struct station* station){ - int count = 0; - if(*station->tracks == NULL || station == NULL){ + if(station == NULL || station->tracks == NULL){ return 0; } - struct car* ptr = *station->tracks; - while (ptr) - { - count++; - ptr = ptr->next; - } - return count; +return 0; } int count_capacity(struct station* station){ - int res = 0; - struct car* ptr = *station->tracks; - while (ptr){ - res += ptr->capacity; - ptr = ptr->next; + if(station == NULL || station->tracks == NULL){ + return 0; + } + int total = 0; + for(int i = 0; itrack_count; i++){ + struct car* ptr = station->tracks[i]; + while(ptr){ + total += ptr->capacity; + ptr = ptr->next; + } } - return res; + return total; }