From 8afedc84ac66fb12b6cc5179c0f7f1fa193027be Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Mon, 2 Nov 2020 12:12:53 +0100 Subject: [PATCH] add --- cv5/a_train.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cv5/a_train.c b/cv5/a_train.c index 760df97..94f2419 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -7,9 +7,13 @@ struct car* add_car(struct car* first,const char* target) { struct car* newcar = calloc(1, sizeof(struct car)); strcpy(newcar->value, target); + if(first == NULL){ return newcar; } + if(first->next == NULL){ + first->next = newcar; + } struct car *this = first; while(this->next != NULL){ this = this->next; @@ -36,6 +40,7 @@ void cancel_train(struct car* first) { exit(0); } if(first->next == NULL){ + printf("Tam je null"); struct car* this = first; first = first->next; free(this);