From 8e6497b6e8bce262610f948bab652f1f67b91727 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Mon, 2 Nov 2020 16:47:32 +0100 Subject: [PATCH] train --- cv5/a_train.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index c650eea..632e564 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -14,9 +14,11 @@ struct car* add_car(struct car* first,const char* target) { if(first == NULL){ strcpy(newcar->value, target); + newcar->next = NULL; return newcar; } - strcpy(newcar->value,target); + strcpy(newcar->value,target); + newcar->next = NULL; struct car *this = first; while(this->next != NULL){ this = this->next; @@ -49,7 +51,7 @@ void cancel_train(struct car* first) { cancel_train(first->next); first->next = NULL; } - if(first->next == NULL){ + else if(first->next == NULL){ free(first); // cancel_train(first->next); } @@ -60,6 +62,9 @@ void cancel_train(struct car* first) { struct car* clear_train(struct car* first, const char* target) { + if(first == NULL){ + return 0; + } struct car* this = first; while(this != NULL){ if(this->value == target){