From ee1ec269b4914f7d9feef677da3672e4fd0126c8 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Sun, 2 Aug 2020 21:56:11 +0700 Subject: [PATCH] Updated find failed students --- data/students.test.txt | 14 +++++++++++++- work1/single.c | 14 +++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/data/students.test.txt b/data/students.test.txt index d897ea8..343a3c6 100644 --- a/data/students.test.txt +++ b/data/students.test.txt @@ -5,4 +5,16 @@ Computer 88 98 52 -95 \ No newline at end of file +95 +Sambo +12345 +CS90 +2 +50 +40 +Chea +6789 +CS78 +2 +50 +20 \ No newline at end of file diff --git a/work1/single.c b/work1/single.c index 1ea50e8..135a408 100644 --- a/work1/single.c +++ b/work1/single.c @@ -282,7 +282,9 @@ int find_min_in_array(int *array) } int min = array[0]; - for (int i = 1; i < sizeof array; i++) + size_t size = sizeof(array) / sizeof(array[0]); + + for (int i = 1; i < size; i++) { if (array[i] < min) { @@ -298,7 +300,9 @@ STUDENT *find_failed_mark(int upper_mark) while (temp != NULL) { - if (find_min_in_array(temp->course_info.marks) < upper_mark) + int min = find_min_in_array(temp->course_info.marks); + + if (min < upper_mark) { if (failed_students == NULL) { @@ -325,7 +329,7 @@ void find_maximum() STUDENT *max_student = find_maximum_avg(); if (max_student == NULL) { - printf("No maximum student found!"); + printf("\nNo maximum student found!\n"); return; } @@ -339,7 +343,7 @@ void find_failed() STUDENT *failed_students = find_failed_mark(upper_mark); if (failed_students == NULL) { - printf("No failed student found!"); + printf("\nNo failed student found!\n"); return; } @@ -405,7 +409,7 @@ again: fclose(file); - printf("\nSaved"); + printf("\nRecord saved successfully!"); // reload data into linked list again read_file();