fprintf (). :
...
#include <stdio.h>
#include <io.h>
...
struct TZap{
char FIO[30];
double s_b;
} Zap;
int size = sizeof(TZap);
FILE *Fz, *Ft;
char File_Zap[] = "zapisi.dat";
char File_Rez[] = "rezult.txt";
void Out(TZap);
void main()
{
int kod, D_f, i=0, j, kol;
long len;
TZap st, *mas_Z;
Ft = fopen(File_Rez, "w");
while(true) {
puts("\n Create 1\n Add 2\n View 3\n Sort 4\n EXIT 0");
scanf("%d", &kod);
switch(kod) {
case 1:
if ((Fz=fopen(File_Zap,"wb"))==NULL) {
puts("\n Create ERROR!");
return;
}
fclose(Fz);
printf("\n Create New File %s!\n",File_Zap);
break;
case 2:
Fz = fopen(File_Zap,"ab");
printf("\n F.I.O. ");
fflush(stdin);
gets(Zap.FIO);
printf(" Ball ");
scanf("%lf", &Zap.s_b);
fwrite(&Zap, size, 1, Fz);
fclose(Fz);
break;
case 3:
if ((Fz=fopen(File_Zap,"rb"))==NULL) {
puts("\n Open ERROR!");
return;
}
//
printf("\n\t--------- Informations ---------");
// Ft
fprintf(Ft,"\n\t--------- Informations ---------");
while(1) {
if(!fread(&Zap,size,1,Fz)) break;
Out(Zap);
}
fclose(Fz);
break;
case 4:
Fz = fopen(File_Zap,"rb");
D_f = fileno(Fz);
len = filelength(D_f);
kol = len/size;
mas_Z = new TZap[kol];
//
for (i=0; i < kol; i++)
fread((mas_Z+i), size, 1, Fz);
fclose(Fz);
printf("\n\t----- S O R T -----\n");
fprintf(Ft,"\n\t----- S O R T -----\n");
for (i=0; i < kol-1; i++)
for (j=i+1; j < kol; j++)
if (mas_Z[i].s_b > mas_Z[j].s_b) {
|
|
st = mas_Z[i];
mas_Z[i] = mas_Z[j];
mas_Z[j] = st;
}
for (i=0; i<kol; i++)
Out(mas_Z[i]);
delete []mas_Z;
break;
case 0:
fclose(Ft);
return;
}
}
}
//----------------- --------------------
void Out(TZap z)
{
printf("\n %20s, %6.3lf.", z.FIO,z.s_b);
fprintf(Ft, "\n %20s, %6.3lf.", z.FIO, z.s_b);
}
1, zapisi. dat, ( ). , 2, 4 . 3, , ( ), 4. :
, : , , ( ), .
:
;
;
;
: , , , ;
.
, .
.
1. , 8, 9 10.
2. -, .
3. - .
4. , , 8 9.
5. , 4 5 8 .
6. . , .
7. , 4 .
8. .
9. , .
10. , ( 4).
11. , 9 10 .
12. , 7 8 9 10 .
13. , .
|
|
14. - .
15. , .
16. , 8 9 .