-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.h
108 lines (78 loc) · 2.11 KB
/
database.h
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
/*
*Function: updateFile
*used to update file
*upDate is pointer
*
*void func
*/
void updateFile(struct employee *upDate)
{
fpointer = fopen(DB, "w");
while (upDate != NULL)
{
if (upDate->id != start->id)
{
fprintf(fpointer, "\n");
}
fprintf(fpointer, "%d;%s;%s;%d;%.2f", upDate->id, upDate->fname, upDate->lname, upDate->age, upDate->salary);
upDate = upDate->next;
}
fclose(fpointer);
}
/*
*Function: insertLinkedListFromFile
*used to update the new_id
*
*id is int number = id
*fname is string = the first name
*lname is string = the last name
*age is int num = age
*salary is float num = salary
*
*void func
*/
void insertLinkedListFromFile(int id, char fname[], char lname[], int age, float salary)
{
new_id = id;
insertToLinkedList(id, fname, lname, age, salary);
}
/*
*Function: DBconverter
*used to read data from file
*
*void func
*/
void DBconverter()
{
char singleline[100];
FILE *fpointer;
char idstring[20] = "stilVersion!", fnamestring[20], lnamestring[20], agestring[20], salarystring[20];
fpointer = fopen(DB, "r");
while (!feof(fpointer))
{
//ID %[^;] regular expresion
fscanf(fpointer, "%[^;]", idstring);
// Check the idstring has overwritten from file or not
if (strcmp(idstring, "stilVersion!") == 0)
{
// if idstring has not overwritten, then the file contains only a new line.
return;
}
fseek(fpointer, 1, SEEK_CUR);
//FNAME
fscanf(fpointer, "%[^;]", fnamestring);
strcpy(fnamestring, upperLower(fnamestring));
fseek(fpointer, 1, SEEK_CUR);
//LNAME
fscanf(fpointer, "%[^;]", lnamestring);
strcpy(lnamestring, upperLower(lnamestring));
fseek(fpointer, 1, SEEK_CUR);
//AGE
fscanf(fpointer, "%[^;]", agestring);
fseek(fpointer, 1, SEEK_CUR);
//SALARY
fscanf(fpointer, "%[^\n]", salarystring);
insertLinkedListFromFile(stringToint(idstring), fnamestring, lnamestring, stringToint(agestring), stringTofloat(salarystring));
}
fclose(fpointer);
}