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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
| #include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
void main()
{
typedef struct
{ char charvar[30];
float floatvar;
int intvar;
} Info;
Info data;
int i,n,newint,c,siz,m,z;
int num;
char newch,newst[30],ch;
FILE *myfile;
FILE *myfile2;
menu:
clrscr();
printf("1 - Vvod\n");
printf("2 - Chtenie\n");
printf("3 - Dobavlenie\n");
printf("4 - Redaktirovanie\n");
printf("5 - Ydalenie\n");
ch=getch();
switch (ch) {
case 49: {
//====================ÓÓÐÐÐÀÀ!! Çàïèñü!============
myfile = fopen("D:/hardware.dat","wb");
printf("Vvod dannuh o tovarax:\n");
i=1;
do
{ printf("\n N/N: %d\n",i);
printf("\n Nazvanie --> ");
scanf("%s",&data.charvar);
printf("\n Stoumost' --> ");
scanf("%f",&data.floatvar);
printf("\n Kolichestvo --> ");
scanf("%d",&data.intvar);
fwrite(&data,sizeof(Info),1,myfile);
i++;
printf("\nProdolzhit vvod tovarov?? Esc - net , Enter - da ");
newch=getch();
printf("\n");
} while (newch!=27);
fclose(myfile);goto menu; } break;
//===================Äîáàâëåíèå ïîëó÷èëîñü ñ 1 ðàçà))======
case 51:{
myfile = fopen("D:/hardware.dat","ab");
printf("Dobavlenie:\n");
do
{printf("\n Nazvanie --> ");
gets(data.charvar);
printf("\n Stoumost' --> ");
scanf("%f",&data.floatvar);
printf("\n Kolichestvo --> ");
scanf("%d",&data.intvar);
fwrite(&data,sizeof(Info),1,myfile);
printf("\nProdolzhit vvod tovarov?? Esc - net , Enter - da ");
newch=getch();
printf("\n");
} while (newch!=27);
fclose(myfile);goto menu;
}break;
case 50:{
//======================×òåíèå 2 ============
printf("Vuvid dannuh o tovare:\n");
myfile=fopen("D:/hardware.dat","rb"); //
i=1;
fread(&data,sizeof(Info),1,myfile);
do
{
printf("N\N: %d | Nazvanie: %s Stoimost': %3.2f Kolichestvo: %d \n",i,data.charvar,data.floatvar,data.intvar);
fread(&data,sizeof(Info),1,myfile);
i++;
}
while (!feof(myfile));
fclose(myfile);
getch(); goto menu;}break;
//========================Ïîèñê==============================
case 52: {
printf("Edit:\n");
myfile=fopen("D:/hardware.dat","rb+"); // îòêðûòèå áèíàðíîãî ôàéëà äëÿ ÷òåíèÿ
printf("Nomer tovara -->");
scanf("%d",&siz);
i=1;
label1:
fread(&data,sizeof(Info),1,myfile);
if (siz==i)
{printf("\n N\N: %d \n\n",i); printf(" Nazvanie:"); puts(data.charvar);printf("\n");printf(" Stoimost': %3.2f\n\n Kolichestvo: %d \n\n",data.floatvar,data.intvar);
} else {
i++; goto label1; } ;
printf("name ->"); scanf("%s",&data.charvar);
printf("cena ->"); scanf("%f",&data.floatvar);
printf("kol->");scanf("%d",&data.intvar);
fseek(myfile,-sizeof(Info),i);
fwrite(&data,sizeof(Info),1,myfile);
break;}
case 53:
{
clrscr();
printf("Vuvod dannuh o tovare:\n");
myfile=fopen("D:/ware.dat","rb");
n=0;
printf("\nBEFORE FREAD OF FILE: N=%d",n);
fseek( myfile, 0, 2 );
n = ftell(myfile) / sizeof(Info);
printf("\nAFTER COUNTING OF FILE: N=%d",n);
rewind(myfile);
printf("\nNazvanue------>");
scanf("%s",&newst);
myfile2=fopen("D:/hardware1.dat","wb");
//i=1;
for(i=0;i<n-1;++i)
{ fread(&data,sizeof(Info),1,myfile);
if(strcmp(newst,data.charvar)!=0)
fwrite(&data,sizeof(Info),1,myfile2) ;
// i++;
}
//while(!feof(myfile));
fclose(myfile);
fclose(myfile2);
printf("\n--->>%d",i);
myfile2=fopen("D:/hardware1.dat","rb");
//i=1;
myfile=fopen("D:/hardware.dat","wb");
for(i=0;i<n-1;++i)
{
fread(&data,sizeof(Info),1,myfile2);
fwrite(&data,sizeof(Info),1,myfile) ;
}
//while (!feof(myfile2));
fclose(myfile);
fclose(myfile2);
//printf("\n--->>>%d",i);
getch();
goto menu; }break;
} } |