Код: Выделить всё
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define n putchar('\n');
main()
{
FILE *f;
struct sportsman
{
char surname[8];
int number;
int points;
} a,b[10];
puts("Enter info about sportsman");
n;
int i=0,k=0; char c,t[8];
f=fopen("sportsman.txt","w");
do
{
printf("Sportsman #%d: ",i+1);
scanf("%s %d %d",&a.surname,&a.number,&a.points);
fwrite(&a,sizeof(a),1,f);
k++; i++;
printf("End?[y]");
c=getch();
n;
}
while(c != 'y');
fclose(f);
i=0;
f=fopen("sportsman.txt","r");
fread(&a,sizeof(a),1,f);
while(!feof(f))
{
strcpy(b[i].surname,a.surname);
b[i].number=a.number;
b[i].points=a.points;
fread(&a,sizeof(a),1,f);
i++;
}
fclose(f);
strcpy(t,b[2].surname); strcpy(b[2].surname,b[1].surname); strcpy(b[1].surname,t);
f=fopen("sportsman.txt","w");
for(i=0; i < k; i++)
{
fwrite(&b[i],sizeof(b[i]),1,f);
}
fclose(f);
getch();
return 0;
}