-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbUpdate.c
More file actions
64 lines (54 loc) · 1.66 KB
/
Copy pathdbUpdate.c
File metadata and controls
64 lines (54 loc) · 1.66 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
#pragma pack(1)
#include "dbUpdate.h"
#include "dbFilesHandler.h"
#include "dbRead.h"
#include "dbStructures.h"
#include <stdio.h>
void updateM() {
shop updShop = getM();
if (updShop.isActive) {
printf("\\\\ Enter new address: ");
fflush(stdin);
gets(updShop.address);
printf("\n\n/ Updated shop:\t/\n");
formatShopOutput(&updShop);
updateShop(&updShop);
}
}
void updateS() {
employee updEmployee = getS();
if (updEmployee.isActive) {
printf("\\\\ Enter new first name: ");
fflush(stdin);
gets(updEmployee.firstName);
printf("\\\\ Enter new last name: ");
fflush(stdin);
gets(updEmployee.lastName);
printf("\n\n/ Updated employee:\t/\n");
formatEmployeeOutput(&updEmployee);
updateEmployee(&updEmployee);
}
}
void updateShop(const shop *updShop) {
FILE *shopDataFile = NULL;
openDbFile(&shopDataFile, shopsData);
unsigned long shopAddress = getAddressByKey(updShop->id, shopsData);
fseek(shopDataFile, (long)shopAddress, SEEK_SET);
fwrite(&*updShop, sizeof(shop), 1, shopDataFile);
fclose(shopDataFile);
}
void updateEmployee(const employee *updEmployee) {
FILE *employeeDataFile = NULL;
openDbFile(&employeeDataFile, employeesData);
unsigned long employeeAddress =
getAddressByKey(updEmployee->id, employeesData);
fseek(employeeDataFile, (long)employeeAddress, SEEK_SET);
fwrite(&*updEmployee, sizeof(employee), 1, employeeDataFile);
fclose(employeeDataFile);
}
void updateTrashZone(const trashZone *updTrashZone) {
FILE *trashZoneFile = NULL;
openDbFile(&trashZoneFile, trashZoneData);
fwrite(&*updTrashZone, sizeof(trashZone), 1, trashZoneFile);
fclose(trashZoneFile);
}