Preform the linked list nodes

Use free to clean up the memory
This commit is contained in:
Sambo Chea 2020-08-02 19:42:42 +07:00
parent 909f55f621
commit ff0e21d42b

View File

@ -287,12 +287,23 @@ again:
fclose(file); fclose(file);
printf("\nSaved"); printf("\nSaved");
// reload data into linked list again
read_file();
} }
void read_file() void read_file()
{ {
// init head to null // free the nodes
head = NULL; // 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 *file;
file = fopen(FILE_STUDENT_DATA_PATH, "r"); file = fopen(FILE_STUDENT_DATA_PATH, "r");