Fixed for empty record when use option find max or any else

This commit is contained in:
Sambo Chea 2020-08-02 22:03:08 +07:00
parent 1007604842
commit c5416d4704

View File

@ -236,6 +236,9 @@ void search_student()
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE]) STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
{ {
// refresh data from file first
read_file();
STUDENT *temp = head; STUDENT *temp = head;
while (temp != NULL) while (temp != NULL)
@ -253,6 +256,9 @@ STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
STUDENT *find_maximum_avg() STUDENT *find_maximum_avg()
{ {
// refresh data from file first
read_file();
STUDENT *temp = head, *max; STUDENT *temp = head, *max;
max = temp->next; max = temp->next;
@ -271,8 +277,10 @@ STUDENT *find_maximum_avg()
temp = temp->next; temp = temp->next;
} }
// release the max next record
// set max next element to NULL // set max next element to NULL
// because we use only one record // because we use only one record
release(max->next);
max->next = NULL; max->next = NULL;
return max; return max;
@ -300,6 +308,9 @@ int find_min_in_array(int *array)
STUDENT *find_failed_mark(int upper_mark) STUDENT *find_failed_mark(int upper_mark)
{ {
// refresh data from file first
read_file();
STUDENT *temp = head, *failed_students = NULL; STUDENT *temp = head, *failed_students = NULL;
while (temp != NULL) while (temp != NULL)