Compare commits
3 Commits
5d13eb0e38
...
b3ddc90786
Author | SHA1 | Date | |
---|---|---|---|
b3ddc90786 | |||
ef484509f3 | |||
55a392584e |
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"typeinfo": "c"
|
||||||
|
}
|
||||||
|
}
|
@ -6,24 +6,3 @@ Computer
|
|||||||
98
|
98
|
||||||
52
|
52
|
||||||
95
|
95
|
||||||
SS
|
|
||||||
323
|
|
||||||
SC
|
|
||||||
3
|
|
||||||
2
|
|
||||||
4
|
|
||||||
2
|
|
||||||
Sambo2
|
|
||||||
73823
|
|
||||||
MSK2
|
|
||||||
3
|
|
||||||
3
|
|
||||||
54
|
|
||||||
2
|
|
||||||
SS
|
|
||||||
SS3
|
|
||||||
212
|
|
||||||
3
|
|
||||||
5
|
|
||||||
3
|
|
||||||
2
|
|
100
work1/single.c
100
work1/single.c
@ -1,8 +1,10 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE 128
|
#define BUFFER_SIZE 128
|
||||||
#define MAX_NO_OF_UNITS 4
|
#define MAX_NO_OF_UNITS 4
|
||||||
|
#define NAME_SIZE 20
|
||||||
|
|
||||||
const char *FILE_STUDENT_DATA_PATH = "./data/students.test.txt";
|
const char *FILE_STUDENT_DATA_PATH = "./data/students.test.txt";
|
||||||
|
|
||||||
@ -36,6 +38,8 @@ typedef struct student_tag STUDENT;
|
|||||||
void display_menu();
|
void display_menu();
|
||||||
void print_welcome();
|
void print_welcome();
|
||||||
void print_student(STUDENT *student);
|
void print_student(STUDENT *student);
|
||||||
|
void release(STUDENT *data);
|
||||||
|
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE]);
|
||||||
|
|
||||||
// core functions
|
// core functions
|
||||||
void display_students();
|
void display_students();
|
||||||
@ -100,13 +104,9 @@ void print_welcome()
|
|||||||
|
|
||||||
void display_students()
|
void display_students()
|
||||||
{
|
{
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
read_file();
|
read_file();
|
||||||
|
|
||||||
STUDENT *student;
|
STUDENT *student = head;
|
||||||
|
|
||||||
student = head;
|
|
||||||
|
|
||||||
if (student == NULL)
|
if (student == NULL)
|
||||||
{
|
{
|
||||||
@ -114,20 +114,15 @@ void display_students()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n================ Student Details ================\n");
|
|
||||||
|
|
||||||
print_student(student);
|
print_student(student);
|
||||||
|
|
||||||
while (student->next != NULL)
|
|
||||||
{
|
|
||||||
printf("\n");
|
|
||||||
student = student->next;
|
|
||||||
print_student(student);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_student(STUDENT *student)
|
void print_student(STUDENT *student)
|
||||||
{
|
{
|
||||||
|
printf("\n================ Student Details ================\n");
|
||||||
|
while (student != NULL)
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
printf("Student Name: %s\n", student->student_info.name);
|
printf("Student Name: %s\n", student->student_info.name);
|
||||||
printf("Student ID: %s\n", student->student_info.id);
|
printf("Student ID: %s\n", student->student_info.id);
|
||||||
printf("Course Name: %s\n", student->course_info.course_name);
|
printf("Course Name: %s\n", student->course_info.course_name);
|
||||||
@ -140,6 +135,13 @@ void print_student(STUDENT *student)
|
|||||||
}
|
}
|
||||||
printf("]\n");
|
printf("]\n");
|
||||||
printf("Avg: %.2f\n", student->course_info.avg);
|
printf("Avg: %.2f\n", student->course_info.avg);
|
||||||
|
student = student->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean up the memory
|
||||||
|
// after output the data
|
||||||
|
// because we don;t need it anymore after output
|
||||||
|
release(student);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_menu()
|
void display_menu()
|
||||||
@ -157,11 +159,11 @@ void add_student(char student_name[20], char student_id[10], char course_name[20
|
|||||||
STUDENT *temp, *iterator;
|
STUDENT *temp, *iterator;
|
||||||
temp = (struct student_tag *)malloc(sizeof(struct student_tag));
|
temp = (struct student_tag *)malloc(sizeof(struct student_tag));
|
||||||
PERSON info;
|
PERSON info;
|
||||||
strncpy(info.name, student_name, 20);
|
memcpy(info.name, student_name, 20);
|
||||||
strncpy(info.id, student_id, 10);
|
memcpy(info.id, student_id, 10);
|
||||||
|
|
||||||
COURSE course;
|
COURSE course;
|
||||||
strncpy(course.course_name, course_name, 20);
|
memcpy(course.course_name, course_name, 20);
|
||||||
course.no_of_units = no_of_units;
|
course.no_of_units = no_of_units;
|
||||||
// memcpy(course.marks, marks);
|
// memcpy(course.marks, marks);
|
||||||
|
|
||||||
@ -215,7 +217,36 @@ int count()
|
|||||||
|
|
||||||
void search_student()
|
void search_student()
|
||||||
{
|
{
|
||||||
printf("\nNot implement yet!");
|
char search_key[NAME_SIZE];
|
||||||
|
|
||||||
|
printf("Enter student name or id to search: ");
|
||||||
|
scanf("%s", &search_key);
|
||||||
|
|
||||||
|
STUDENT *found_student = search_student_by_name_or_id(search_key);
|
||||||
|
if (found_student == NULL)
|
||||||
|
{
|
||||||
|
printf("No student found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_student(found_student);
|
||||||
|
}
|
||||||
|
|
||||||
|
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
|
||||||
|
{
|
||||||
|
STUDENT *temp = head;
|
||||||
|
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
if (strcmp(temp->student_info.name, search_key) == 0 || strcmp(temp->student_info.id, search_key) == 0)
|
||||||
|
{
|
||||||
|
printf("\nSearch found with key: %s\n", search_key);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_maximum()
|
void find_maximum()
|
||||||
@ -252,9 +283,9 @@ again:
|
|||||||
printf("Enter no of units: ");
|
printf("Enter no of units: ");
|
||||||
scanf("%d", &no_of_units);
|
scanf("%d", &no_of_units);
|
||||||
|
|
||||||
if (no_of_units > MAX_NO_OF_UNITS)
|
if (no_of_units > MAX_NO_OF_UNITS && no_of_units <= 0)
|
||||||
{
|
{
|
||||||
printf("you cannot input the units bigger than %d\n", MAX_NO_OF_UNITS);
|
printf("you cannot input the units bigger than %d or less than 0\n", MAX_NO_OF_UNITS);
|
||||||
getchar();
|
getchar();
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
@ -294,10 +325,10 @@ again:
|
|||||||
|
|
||||||
void read_file()
|
void read_file()
|
||||||
{
|
{
|
||||||
// free the nodes
|
// release nodes
|
||||||
// because it can be use in memory
|
// we need to clean up the memory
|
||||||
// we need to clear it first
|
if (head != NULL)
|
||||||
// before we re-initailize the new data
|
{
|
||||||
STUDENT *temp;
|
STUDENT *temp;
|
||||||
while (head != NULL)
|
while (head != NULL)
|
||||||
{
|
{
|
||||||
@ -305,6 +336,7 @@ void read_file()
|
|||||||
head = head->next;
|
head = head->next;
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
file = fopen(FILE_STUDENT_DATA_PATH, "r");
|
file = fopen(FILE_STUDENT_DATA_PATH, "r");
|
||||||
@ -376,3 +408,23 @@ void quite()
|
|||||||
printf("\nGoodbye!");
|
printf("\nGoodbye!");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void release(STUDENT *data)
|
||||||
|
{
|
||||||
|
if (data == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (data != NULL)
|
||||||
|
{
|
||||||
|
temp = data;
|
||||||
|
data = data->next;
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user