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){