This commit is contained in:
Maryna Kravtsova 2020-11-03 18:30:23 +01:00
parent 3ff32fafa1
commit 97472d25cf

View File

@ -64,11 +64,16 @@ struct car* clear_train(struct car* first, const char* target) {
while(first != NULL){ while(first != NULL){
int x = strcmp(this->value, target); int x = strcmp(this->value, target);
if(x == 0){ if(x == 0){
struct car* temp = this->next; struct car* prev = this;
strcpy(this->value,temp->value); struct car* node = this->next;
free(temp); while(prev != NULL && node != NULL){
free(temp->value); prev->next = node->next;
return 0; free(node);
prev = prev->next;
if(prev != NULL){
node = prev->next;
}
}
} }
this = this->next; this = this->next;
} }