From 43082a4100ec47a7cd9e3987ae2339fa6bc5dda4 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Thu, 4 Nov 2021 23:55:06 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'cv4/a=5Ftrain.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv4/a_train.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cv4/a_train.c b/cv4/a_train.c index fe22a14..298bc60 100644 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -7,9 +7,16 @@ struct car* add_car(struct car* first, const char* target){ if(!strcmp(target, "")) return NULL; + if(!first){ + first = (struct car*)calloc(1, sizeof(struct car)); + strcpy(first->value, target); + first->next = NULL; + return first; + } + struct car* temp = first; - while(temp != NULL) + while(temp->next != NULL) temp = temp->next; temp->next = (struct car*)calloc(1, sizeof(struct car));