-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint_Fn.c
103 lines (97 loc) · 2.48 KB
/
Print_Fn.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Ansi_Colors.h"
#include "Structs.h"
#include "Print_Fn.h"
int DobComN(Data data1, Data data2)
{
char *p1 = data1.lname;
char *p2 = data2.lname;
while(*p1 != '\0')
{
if(*p1 >= 'A' && *p1 <= 'Z')
{
*p1 += 32;
}
p1++;
}
while(*p2 != '\0')
{
if(*p2 >= 'A' && *p2 <= 'Z')
{
*p2 += 32;
}
p2++;
}
if(strcmp(data1.lname, data2.lname) == 1)
{
return 1;
}
else
{
return 0;
}
}
void sortByLname(Data *TheData, Birth *TheBirth, int NOL)
{
int ToF = 1;
while(ToF)
{
ToF = 0;
for(int i = 0; i < (NOL - 1); i++)
{
if(DobComN(*(TheData + i), *(TheData + i + 1)))
{
ToF = 1;
Swap_Fn(TheData, TheBirth, i);
}
}
}
}
int DobComB(Birth birth1, Birth birth2)
{
return ((atoi(birth1.year) * 10000 + atoi(birth1.month) * 100 + atoi(birth1.day))-(atoi(birth2.year) * 10000 + atoi(birth2.month) * 100 + atoi(birth2.day)));
}
void Swap_Fn(Data *TheData, Birth *TheBirth, int i)
{
Data NewData;
Birth NewBirth;
NewData = *(TheData + i);
NewBirth = *(TheBirth + i);
*(TheData + i) = *(TheData + i + 1);
*(TheBirth + i) = *(TheBirth + (i + 1));
*(TheData + (i + 1)) = NewData;
*(TheBirth + (i + 1)) = NewBirth;
}
void SortByDOB(Data *TheData, Birth *TheBirth, int NOL)
{
int ToF = 1;
while(ToF)
{
ToF = 0;
for(int i = 0; i < (NOL - 1); i++)
{
if(DobComB(*(TheBirth + i), *(TheBirth + i + 1)) > 0)
{
ToF = 1;
Swap_Fn(TheData, TheBirth, i);
}
}
}
}
void Print_Fn(Data *TheData, Birth *TheBirth, int NOL)
{
for(int i = 0; i < NOL; i++)
{
printf("%d-\n", i + 1);
printf("First name: %s\n",(TheData + i)->fname);
printf("Last name: %s\n",(TheData + i)->lname);
printf("Address: %s\n",(TheData + i)->adress);
printf("Phone Number: %s\n",(TheData + i)->number);
printf("Email: %s\n",(TheData + i)->email);
printf("Data of birth: %s-%s-%s\n",(TheBirth + i)->day, (TheBirth + i)->month, (TheBirth + i)->year);
printf(ANSI_COLOR_BLUE "---------------\n" ANSI_COLOR_RESET);
}
}