From 8ee8f39555f85a9b7deb4a27dbc078d7d5177864 Mon Sep 17 00:00:00 2001 From: Anzhelika Nikolaieva Date: Sat, 11 Nov 2023 15:46:45 +0000 Subject: [PATCH] Update 'cv7/a_station.c' --- cv7/a_station.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cv7/a_station.c b/cv7/a_station.c index 9f418dd..a4b9e41 100644 --- a/cv7/a_station.c +++ b/cv7/a_station.c @@ -33,12 +33,19 @@ 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); + int track = select_track(station, target); struct car* new_car = (struct car*)malloc(sizeof(struct car)); - strncpy(new_car->value, target, TARGET_SIZE); - new_car->capacity = capacity; - new_car->next = station->tracks[track]; - station->tracks[track] = new_car; + + strncpy(new_car->value, target, TARGET_SIZE); + new_car->capacity = capacity; + new_car->next = NULL; + + if (station->tracks[track] == NULL) { + station->tracks[track] = new_car; + } else { + new_car->next = station->tracks[track]; + station->tracks[track] = new_car; + } }