From 97472d25cfec8ef0560a755411e1b1aee3c90be7 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Tue, 3 Nov 2020 18:30:23 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 5f81bed..110088b 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -64,11 +64,16 @@ struct car* clear_train(struct car* first, const char* target) { while(first != NULL){ int x = strcmp(this->value, target); if(x == 0){ - struct car* temp = this->next; - strcpy(this->value,temp->value); - free(temp); - free(temp->value); - return 0; + struct car* prev = this; + struct car* node = this->next; + while(prev != NULL && node != NULL){ + prev->next = node->next; + free(node); + prev = prev->next; + if(prev != NULL){ + node = prev->next; + } + } } this = this->next; }