From 51e095e6c0b66a25ffb3c5392a4158178ed66bbd Mon Sep 17 00:00:00 2001 From: Bohdan Kapliuk Date: Tue, 15 Oct 2024 14:31:43 +0300 Subject: [PATCH] cv4 --- cv4/a_train.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cv4/a_train.c b/cv4/a_train.c index 3ecfbc8..8f276b8 100644 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -2,13 +2,28 @@ #include struct car* add_car(struct car* first,const char* target) { - return NULL; + struct car* newcar = calloc(1,sizeof(struct car)); + strcpy(newcar->value, target); + struct car* this = first; + while (this->next != NULL) { + this = this->next; + } + this->next = newcar; + return first; } void print_train(struct car* first) { + while(first != NULL)( + printf("%s", first->value); + first->value = first->next + ) } void cancel_train(struct car* first) { + while(first != NULL){ + free(first->next); + first = first->next; + } }