include conio include math include stdio include string struct type ch

 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
#include<conio.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
struct type { char A[7]; int cost[10]; int kol[20];};
struct table { type elem[10]; int n;};
struct type2 { char A[7]; char cost[10]; };
struct table2 { type2 elem[10]; int n;};
FILE *fp;
FILE *f;
type *el ()
{
type *el = new type;
fscanf(fp,"%s %d %d", el->A, &el->cost, &el->kol);
return el; }
type2 *el1 ()
{
type2 *el = new type2;
fscanf(f,"%s %d", el->A, &el->cost);
return el; }
void sdvig (table *t, int i)
{
for (i; i<t->n; i++) t->elem[i]=t->elem[i+1];
t->n--; }
int search(table *t, type2 *el)
{ int i=0;
for(i;i<=t->n;i++)
{ if (strcmp(el->A,t->elem[i].A)==0) return i; }}
void add(type *el, table *t)
{ int i=0, F=1;
for(i=0;i<t->n && F; i++)
{ if ( strcmp(el->A,t->elem[i].A)>0) F=0;}
int num=i;
t->n++;
for(i=t->n;i>=num;i++)
{ t->elem[i]=t->elem[i-1];}
t->elem[num]=*el;}
void main()
{ clrscr();
table *t;
table2 *t2;
type *ele;
type2 *elemen;
int i,k,l=-1;
t=new table;
ele=new type;
t2=new table2;
elemen=new type2;
t->n=0;
fp=fopen("shop.txt","r");
f=fopen("buy.txt","r");
/*for(i=0;!feof(fp);i++)
{
if(t->n<10)
{ ele=el();
for(k=i;k!=0;k--)
{
if(strcmp(t->elem[k-1].A,ele->A)<0) { //*ele=t->elem[k];
t->elem[k-1]=t->elem[k]; }
else break; }
t->elem[k]=*ele;
t->n++; }
*/
for(i=0;!feof(fp);i++)
{ if (t->n<10)
{ ele=el();
add(ele,t); }
else {printf("perepolnenie");break;}}
t->n--;
fclose(fp);
/*for(i=0;!feof(f);i++)
{
if(t2->n<10)
{ elemen=el1();
t2->elem[i]=*elemen;
l=search(t,elemen);
if (l!=-1) sdvig(t,l);
}
else break;} */
for(k=0;k<=t->n;k++)
{
printf("%s %d %d \n",t->elem[k].A,t->elem[k].cost,t->elem[k].kol);}
fclose(f);
getch();}