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
| #include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <fstream.h>
typedef struct RESULT
{int min;
int sec;
};
typedef struct SPORT
{char surname[20];
char name[20];
int old;
RESULT res;
};
void strct_in(SPORT *sp, int i);
int strct_obr(char []);
void create_bin(char [], char []);
void main()
{
int n;
//SPORT sp[30];
char f1[25], fbin[25];
clrscr();
cout << "Vvedite imena files"<<endl;
cin >> f1;
cout << "VVedite new file";
cin>> fbin;
create_bin (f1,fbin);
// strct_in(sp, i);
n=strct_obr(fbin);
cout<< "mesto="<<n;
getch();
}
void create_bin (char f1[], char fbin[])
{
SPORT sp;
ifstream f(f1);
if (!f) cout << "Error opening";
ofstream f_bin(fbin, ios::binary);
if (!f_bin) cout << "Error ";
while (!f.eof())
{
f >> sp.surname >> sp.name >> sp.old >> sp.res.min >> sp.res.sec;
f_bin.write((char *)&sp,sizeof(SPORT));
}
f_bin.close();
f.close();
}
void strct_in(SPORT *sp, int i)
{
printf (" surname name old rezmin rezsec:\n ");
for (int k=0; k<i; k++)
{
scanf ("%s",&sp[k].surname);
scanf ("%s",&sp[k].name);
scanf ("%d",&sp[k].old);
scanf ("%d",&sp[k].res.min);
scanf ("%d",&sp[k].res.sec);
}
}
int strct_obr(char fbin[])
{
int young,i=0 ,rr, b=0;
SPORT sp;
ifstream f_bin(fbin, ios::binary);
if (!f_bin) {cout << "Error 2";return -1;}
f_bin.read ((char *)&sp, sizeof(SPORT));
young=sp.old;
rr=sp.res.min*60+sp.res.sec;
while (!f_bin.eof())
{
f_bin.read ((char *)&sp, sizeof(SPORT));
if(sp.old < young)
{
young=sp.old; rr=sp.res.min*60+sp.res.sec;
}
}
// int rr = sp[k].res.min*60 + sp[k].res.sec
f_bin.seekg(ios::beg);
while (!f_bin.eof())
{
// for (n=0; n<i; n++)
f_bin.read ((char *)&sp, sizeof(SPORT));
if (sp.res.min*60+sp.res.sec < rr) b++;
}
f_bin.close();
return b+1;
} |