-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
106 lines (80 loc) · 1.56 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
#include "cpim.h"
//include this before cvector.h for mystrdup
#include "c_utils.h"
#define CVEC_ONLY_INT
#define CVEC_ONLY_VOID
#define CVECTOR_IMPLEMENTATION
#include "cvector.h"
#define CLIST_IMPLEMENTATION
#include "clist.h"
#include <stdio.h>
int main(int argc, char** argv)
{
cvector_void contacts;
char choice;
int quit = 0;
cvec_void(&contacts, 0, 10, sizeof(contact), free_contact, NULL);
saved = 1;
print_menu();
while (!quit) {
puts("What action would you like to perform?");
choice = read_char(stdin, SPACE_SET, 0, 1);
switch (choice) {
case 'A':
case 'a':
add_contact(&contacts);
break;
case 'D':
case 'd':
display_contacts(&contacts);
break;
case 'E':
case 'e':
edit_contacts(&contacts);
break;
case 'V':
case 'v':
save_contacts(&contacts);
break;
case 'L':
case 'l':
load_contacts(&contacts);
break;
case 'R':
case 'r':
remove_contact(&contacts);
break;
case 'S':
case 's':
sort_contacts(&contacts);
break;
case 'F':
case 'f':
find_contacts(&contacts, NULL, 1);
break;
case 'Q':
case 'q':
//TODO
if (!saved) {
puts("You have unsaved changes! Are you sure you want to quit? (y/N)");
choice = read_char(stdin, SPACE_SET_NO_NEWLINE, 0, 1);
if (choice == 'y' || choice == 'y')
quit = 1;
else
quit = 0;
} else {
quit = 1;
}
break;
case '?':
print_menu();
break;
default:
printf("'%c' is not a valid choice!\n", choice);
print_menu();
}
putchar('\n');
}
cvec_free_void(&contacts);
return 0;
}