-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
83 lines (80 loc) · 2.11 KB
/
main.c
File metadata and controls
83 lines (80 loc) · 2.11 KB
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
#include "header.h"
void main() {
int size_of_Tables, i, choise, Table_num, Quantity;
PTables arr=NULL;
PTableNode temp;
Manot ManotHead;
FILE* instruc,*manot, *out;
char ProductName[51];
ManotHead.head = NULL;
instruc = fopen("Instructions.txt", "r");
if (instruc == NULL)
exit(1);
manot = fopen("Manot.txt", "r");
if (manot == NULL)
exit(1);
out = fopen("output.txt", "w");
if (out == NULL)
exit(1);
fscanf(instruc, "%d", &size_of_Tables);
if (size_of_Tables > 0) {
arr = (PTables)malloc(size_of_Tables * sizeof(Tables));
if (arr == NULL)
fprintf(out, "Allocation to Tables Arr");
for (i = 0; i < size_of_Tables; i++) { //Initialize Tables arr - struct manger
arr[i].head = NULL;
arr[i].bill = 0;
}
}
fscanf(instruc, "%d", &choise); //getting '1' digit to call CreateProducts function
if (CreateProducts(&ManotHead, manot, out) == 0) {
fprintf(out, "Couldn't create manot list");
free(arr);
}
else {
fprintf(out, "The kitchen was created");
while (fscanf(instruc, "%d", &choise) != -1) {
switch (choise)
{
case 2:
fscanf(instruc, "%s", ProductName);
fscanf(instruc, "%d", &Quantity);
AddItems(ProductName, Quantity, ManotHead, out);
break;
case 3:
fscanf(instruc, "%d", &Table_num);
fscanf(instruc, "%s", ProductName);
fscanf(instruc, "%d", &Quantity);
OrderItem(arr, Table_num, ProductName, Quantity, ManotHead, out);
break;
case 4:
fscanf(instruc, "%d", &Table_num);
fscanf(instruc, "%s", ProductName);
fscanf(instruc, "%d", &Quantity);
RemoveItem(arr, Table_num, ProductName, Quantity, ManotHead, out);
break;
case 5:
fscanf(instruc, "%d", &Table_num);
RemoveTable(&arr[Table_num - 1], Table_num, out);
break;
default:
fprintf(out, "\nWrong number of function to excute");
break;
}
}
}
free_Manot(ManotHead.head);
for (i = 0; i < size_of_Tables; i++) { //free all tables
temp = arr[i].head;
while (arr[i].head != NULL) {
arr[i].head = arr[i].head->next;
free(temp->mana_name);
free(temp);
temp = arr[i].head;
}
}
free(arr);
fclose(instruc);
fclose(manot);
fclose(out);
}