From ff0e21d42b43ff771dd1ba1a1b8440e35f378e95 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Sun, 2 Aug 2020 19:42:42 +0700 Subject: [PATCH] Preform the linked list nodes Use free to clean up the memory --- work1/single.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/work1/single.c b/work1/single.c index aa8821b..8266973 100644 --- a/work1/single.c +++ b/work1/single.c @@ -287,12 +287,23 @@ again: fclose(file); printf("\nSaved"); + + // reload data into linked list again + read_file(); } void read_file() { - // init head to null - head = NULL; + // free the nodes + // because it can be use in memory + // we need to clear it first + // before we re-initailize the new data + STUDENT *temp; + while (head != NULL) { + temp = head; + head = head->next; + free(temp); + } FILE *file; file = fopen(FILE_STUDENT_DATA_PATH, "r");