From f458f0780504a3d98a7d821f97453219400b3f4f Mon Sep 17 00:00:00 2001 From: ak643du Date: Wed, 17 Apr 2024 16:02:06 +0200 Subject: [PATCH] Initialization --- cv9/snake.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cv9/snake.c b/cv9/snake.c index 1b1717a..b1843df 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -10,11 +10,23 @@ struct snake* add_snake(struct snake* snake,int x,int y){ } struct snake* remove_snake(struct snake* snake) { - struct snake* temp = snake; - if (snake!= NULL) { - snake = snake->next; - free(temp); + if (snake == NULL) { + return NULL; } + + if (snake->next == NULL) { + free(snake); + return NULL; + } + + struct snake* current = snake; + while (current->next->next != NULL) { + current = current->next; + } + + free(current->next); + current->next = NULL; + return snake; }