-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
98 lines (94 loc) · 2.41 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
#include <stdio.h>
#include <stdlib.h>
#include "subj.h"
#include "List.h"
int DoMenu(char* s[], int len) {
int i;
for (i = 1; i <= len; i++) {
printf("%i. %s\n", i, s[i]);
}
printf("> ");
fflush(stdin);
scanf("%i", &i);
return i<0 || i>len ? 0 : i;
}
int main(void) {
struct List list;
struct Base* item;
enum ItemType type;
char *menuActions[] = {"(none)", "Add Item", "Count", "Print List", "Print Item", "Search By Name", "Search By Code", "Sort List", "Insert", "Delete", "Clear"};
char *typeNames[] = {"(unknown)", "Detail", "FurnitureSet"};
int buffInt;
char *buffStr = (char*)calloc(1, sizeof(char) * 100);
do {
buffInt = DoMenu(menuActions, 9);
switch (buffInt) {
case 1:
type = DoMenu(typeNames, 2);
if (type != None) {
item = Create(type);
InputItem(item);
printf("bilo");
Add(&list, (struct Item*)item);
printf("Item was added!\n\n");
} else {
printf("Wrong item type!\n\n");
}
break;
case 2:
printf("There\'s %i items in list\n\n", Count(&list));
break;
case 3:
PrintSpaceItems(&list);
break;
case 4:
printf("Enter index: ");
scanf("%i", &buffInt);
item = (struct Base*)GetItem(&list, buffInt);
if (item)
PrintItem(item);
break;
case 5:
printf("Enter name: ");
scanf(" %100[^\n]", buffStr);
SearchByName(&list, buffStr);
break;
case 6:
printf("Enter the interval: ");
int start, end = -1;
if (scanf("%d%d", &start, &end) == 2) {
SearchByCode(&list, start, end);
}
break;
case 7:
SortList(&list);
break;
case 8:
printf("Enter index: ");
scanf("%i", &buffInt);
type = DoMenu(typeNames, 2);
if (type != None) {
item = Create(type);
InputItem(item);
Insert(&list, (struct Item*)item, buffInt);
printf("Item was inserted!\n\n");
}
break;
case 9:
printf("Enter index: ");
scanf("%i", &buffInt);
Delete(&list, buffInt);
break;
case 10:
Clear(&list);
printf("List was cleared\n\n");
break;
case -1:
return 0;
break;
default:
printf("Wrong option!\n\n");
break;
}
} while (1);
}