-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-edit-and-delete.c
53 lines (48 loc) · 1.19 KB
/
add-edit-and-delete.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
#include "lib/add-edit-and-delete.h"
#include "lib/all-structs.h"
#include "lib/array.h"
#include <stdlib.h>
#include <stdio.h>
#include "lib/print.h"
#include "lib/search-and-filter.h"
#include "lib/sort.h"
void add(Student *student)
{
sort_subjects_by_string(student->subjects,student->number_of_subjects);
array students=input_array();
students.size++;
push_back(&students.students,student,&students.size);
students.size--;
fprint_students(&students);
free(students.students);
}
void edit(Student *student,Student *edited)
{
sort_subjects_by_string(student->subjects,student->number_of_subjects);
array students=input_array();
int n=students.size;
for(int i=0;i<n;i++)
{
if(cmp(student,&(students.students[i])))
{
students.students[i]=*edited;
break;
}
}
fprint_students(&students);
if(students.size!=0)free(students.students);
}
void delete(Student *student) {
array students=input_array();
int n=students.size;
for(int i=0;i<n;i++)
{
if(cmp(student,&(students.students[i])))
{
element_delete(students.students,&(students.size),i);
break;
}
}
fprint_students(&students);
if(students.size!=0)free(students.students);
}