-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
111 lines (89 loc) · 2.55 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
// Include standard code
#include <stdio.h>
// #include "src/hash_table/hash_table_static.h"
#include "src/string.h"
#include "src/hash_table/hash_table.h"
// Entry pointer
int main(unsigned int argc, const char ** argv) {
init_hash_table();
struct person p1 = {
.name = "Emma Watson",
.age = 31,
.sex = 1
};
struct person p2 = {
.name = "Cara Delevingne",
.age = 28,
.sex = 0
};
struct person p3 = {
.name = "Steve Wozniak",
.age = 70,
.sex = 1
};
struct person p4 = {
.name = "Jeff Bezos",
.age = 57,
.sex = 0
};
struct person p5 = {
.name = "Mark Zuckerberg",
.age = 36,
.sex = 1
};
struct person p6 = {
.name = "Bill Gates",
.age = 65,
.sex = 1
};
struct person p7 = {
.name = "Elon Musk",
.age = 49,
.sex = 1
};
struct person p8 = {
.name = "David Gaspar",
.age = 22,
.sex = 1
};
hash_table_insert(&p1);
hash_table_insert(&p2);
hash_table_insert(&p3);
hash_table_insert(&p4);
hash_table_insert(&p5);
hash_table_insert(&p6);
hash_table_insert(&p7);
hash_table_insert(&p8);
if(argc > 1) {
unsigned int isDelete = FALSE;
for(int i = 1; i < argc; i++) {
// Check cli (delete command)
if(i == 1 && equal(argv[i], "delete")) {
isDelete = TRUE;
continue;
}
if(isDelete) {
// Deleting person
struct person * deleted = hash_table_delete((char *) argv[i]);
if(deleted)
// Show person deleted
printf("[ %s deleted (%s is %i years old) ]\n", deleted->name, deleted->sex ? "He" : "She", deleted->age);
else
// Person not found
printf("[ %s not found ]\n", argv[i]);
} else {
// Lookup person
struct person * found = hash_table_lookup((char *) argv[i]);
if(found != NULL) {
// Show person found
printf("[ %s found ", found->name);
printf("(%s is %i years old) ]\n", found->sex ? "He" : "She", found->age);
} else
// Person not found
printf("[ %s not found ]\n", argv[i]);
}
}
}
print_hash_table();
return 1;
}