add student via cli in menu ready

This commit is contained in:
Sambo Chea 2020-08-02 18:30:52 +07:00
parent b277d96c36
commit 63966b9e34
2 changed files with 75 additions and 12 deletions

View File

@ -6,11 +6,29 @@ Computer
98
52
95
Jon
1101825
Computer
sambo
222
c
1
1
Sambo
728728
CS
4
88
98
52
95
38
32
34
56
CS2
382S
SNS
2
1
3
SHSj
43434
SHS
3
2
5
2

View File

@ -3,7 +3,7 @@
#define BUFFER_SIZE 128
const char *FILE_STUDENT_DATA_PATH = "./data/students.txt";
const char *FILE_STUDENT_DATA_PATH = "./data/students.test.txt";
struct person_tag
{
@ -56,13 +56,12 @@ int main(void)
print_welcome();
display_menu();
while (1)
{
display_menu();
printf("Enter your option: ");
scanf("%d", &selected);
switch (selected)
{
case 1:
@ -264,7 +263,53 @@ void update_file()
{
FILE *file;
file = fopen(FILE_STUDENT_DATA_PATH, "a");
printf("\nNot implement yet!");
char name[20];
char id[10];
char course_name[20];
int no_of_units;
int marks[4];
printf("Enter student name: ");
scanf("%s", &name);
printf("Enter student id: ");
scanf("%s", &id);
printf("Enter course name: ");
scanf("%s", &course_name);
printf("Enter no of units: ");
scanf("%d", &no_of_units);
for (int i = 0; i < no_of_units; i++)
{
printf("Enter mark[%d]: ", i + 1);
scanf("%d", &marks[i]);
}
if (count() > 0)
{
fputs("\n", file);
}
fputs(name, file);
fputs("\n", file);
fputs(id, file);
fputs("\n", file);
fputs(course_name, file);
fputs("\n", file);
fprintf(file, "%d", no_of_units);
for (int i = 0; i < no_of_units; i++)
{
fputs("\n", file);
fprintf(file, "%d", marks[i]);
}
fclose(file);
printf("\nSaved");
}
void read_file()