void AddDATA DATA data ITEM CurrL Head new_node NULL if new_node ITEM

 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
void AddDATA(DATA *data)
{
ITEM *CurrL=Head, *new_node=NULL;
if((new_node=(ITEM *)malloc(sizeof(ITEM)))!=NULL)
{
while(CurrL->next!=NULL)
CurrL=CurrL->next;
if(col!=0)
{
CurrL->next=new_node;
new_node->prev=CurrL;
}
else
{
new_node->prev=NULL;
Head=new_node;
}
new_node->next=NULL;
new_node->data=data;
col++;
}
else
{
error();
}
}
void write_db()
{
FILE *f;
ITEM *Curr;
int zoo;
switch(zoo)
{case 1:
f=fopen("ZOO1.txt","w+t");break;
case 2:
f=fopen("ZOO2.txt","w+t");break;}
if(f!=NULL)
{
fwrite(&LastID, sizeof(long), 1, f);
for(Curr=head->first; Curr!=NULL; Curr=Curr->next)
{
fwrite(Curr->data, sizeof(DATA), 1, f);
}
}
else
{
error();
}
fclose(f);
}
void read_db()
{
FILE *f;
DATA *data;
int zoo;
switch(zoo)
{case 1:
f=fopen("ZOO1.txt","rt");break;
case 2:
f=fopen("ZOO2.txt","rt");break;}
if(f!=NULL)
{
fread(&LastID, sizeof(long), 1, f);
for(;;)
{
if((data=(DATA *)malloc(sizeof(DATA)))!=NULL)
{
if(fread(data, sizeof(DATA), 1, f)!=0)
{
AddDATA(data);
}
else
{
free(data);
break;
}
}
}
}
else
{
error();
}
fclose(f);
}