This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
135 lines (112 loc) · 3.83 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// Created by Manaki ITO on 2020/10/09.
//
#include "main.h"
#define MESSAGE_3 "Input name in KATAKANA AND DO NOT LEAVE SPACE BETWEEN LASTNAME AND SURNAME.\n"
#define MESSAGE_4 "Input number of the student.\n"
#define MESSAGE_5 "Input J.H.S. name in KANJI.\n"
int ask_mode(void);
int print_modes(void);
int ask_parameter(char message[], char user_input[]);
int ask_continue(void);
int main(void) {
int mode;
struct student current_table[101];
int number_of_students;
char user_input[64];
int user_input_int;
printf("================================================\n");
printf(" Welcome to the Student Database System \n");
printf("================================================\n");
number_of_students = load_csv(current_table);
printf("Loading csv file succeeded!\n");
fprintf(stderr, "WARNING: Character code of your terminal and 'records.csv' MUST BE UTF-8.\n");
while(1) {
fflush(stdout);
mode = ask_mode();
printf("Mode %d has been selected.\n", mode);
switch (mode) {
case 1:
order_of_attendance_no(current_table, number_of_students);
break;
case 2:
order_of_name(current_table, number_of_students);
break;
case 3:
ask_parameter(MESSAGE_3, user_input);
find_number_from_name(current_table, number_of_students, user_input);
break;
case 4:
printf("\n");
printf("%s", MESSAGE_4);
scanf("%d", &user_input_int);
if (find_name_from_number(current_table, number_of_students, user_input_int) != 0) {
printf("Student not found or error occurred.\n");
}
break;
case 5:
ask_parameter(MESSAGE_5, user_input);
if (find_all_students_from_jhs_name(current_table, number_of_students, user_input) != 0) {
printf("Student not found or error occurred.\n");
}
break;
case 6:
update_record();
number_of_students = load_csv(current_table);
printf("Update table succeeded!\n");
break;
}
if (!ask_continue()) {
printf("Bye\n");
break;
};
}
return 0;
}
int print_modes(void) {
printf("1) Show all the recodes in ascending order of students' number\n");
printf("2) Show all the recodes in ascending order of students' name\n");
printf("3) Show the student number of the student of specified name\n");
printf("4) Show the student name of the student of specified number\n");
printf("5) Show all the student from J.H.S. of specified name\n");
printf("6) Add new student entry and refresh current table\n");
return 0;
}
int ask_mode(void) {
int user_input;
printf("\n");
print_modes();
printf("\n");
printf("Desire mode number?\n");
while(1) {
scanf("%d", &user_input);
printf("\n");
if (!(1 <= user_input && user_input <= 6)) {
printf("Invalid number has been passed. Please specify within 1 to 6.\n");
continue;
}
break;
}
return user_input;
}
int ask_continue(void) {
int user_input;
printf("\n");
printf("Do you want to continue? (0 / 1)\n");
while(1) {
scanf("%d", &user_input);
printf("\n");
if (!(0 <= user_input && user_input <= 1)) {
printf("Invalid number has been passed. Please specify within 0 to 1.\n");
continue;
}
break;
}
return user_input;
}
int ask_parameter(char message[], char user_input[]) {
printf("\n");
printf("%s", message);
scanf("%s", user_input);
return 0;
}