int save HITEM head запись ITEM curr FILE int textbackground WHITE tex

 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
int save(HITEM *head) //запись
{
ITEM *curr;
FILE *f;
int i;
textbackground(WHITE);
textcolor(BLUE);
f=fopen("C:\\spisok.txt","wt");
if(head->kol!=0)
{
curr=head->first;
while(curr!=NULL)
{
fputs(curr->DATA.name,f);
fprintf(f,"\n");
fputs(curr->DATA.artist,f);
fprintf(f,"\n");
fputs(curr->DATA.genre,f);
fprintf(f,"\n%d %d\n",curr->DATA.bit,curr->DATA.dur);
curr=curr->next;
}
window(1,50,79,50);
cprintf("Успешно сохранено ░");
}
else
{
window(1,50,79,50);
fprintf(f,"\0");
cprintf("Список пустой ░");
}
fclose(f);
return;
}
HITEM* read() // чтение
{
FILE *f;
HITEM *head;
ITEM *curr,*n;
int i;
head=(HITEM*)malloc(sizeof(HITEM));
head->first=NULL;
head->kol=0;
if((f=fopen("C:\\spisok.txt","rt"))==NULL)
{
window(1,50,79,50);
cprintf("Ошибка чтения файла ░");
return head;
}
else
{
if(feof(f)==0)
{
curr=(ITEM*)malloc(sizeof(ITEM));
fgets(curr->DATA.name,14,f);
//fscanf(f,"\n");
fgets(curr->DATA.artist,14,f);
//fscanf(f,"\n");
fgets(curr->DATA.genre,14,f);
fscanf(f,"%d %d\n",&curr->DATA.bit,&curr->DATA.dur);
curr=head->first;
curr->prev=NULL;
while(!feof(f))
{
curr->next=(ITEM*)malloc(sizeof(ITEM));
fgets(curr->next->DATA.name,14,f);
fscanf(f,"\n");
fgets(curr->next->DATA.artist,14,f);
fscanf(f,"\n");
fgets(curr->next->DATA.genre,14,f);
fscanf(f,"\n%d %d\n",&curr->next->DATA.bit,&curr->next->DATA.dur);
curr->next->prev=curr;
curr->next->next=NULL;
curr=curr->next;
head->kol++;
}
window(1,50,79,50);
cprintf("Файл успешно прочитан ░");
fclose(f);
return head;
}
else
{
window(1,50,79,50);
free(curr);
cprintf("Открытый файл пустой ░");
fclose(f);
return head;
}
}
}