发布网友 发布时间:2023-06-25 04:20
共1个回答
热心网友 时间:2023-08-01 03:23
#include <stdio.h>
#dfine N (20)
#define PATH "student.dat"
typedef struct student
{
long num;
char name[10];
int age;
char sex;
char speciality[20];
char address[40];
}STUDENT;
STUDENT a[N];
void WritetoFile(STUDENT stu[],int n)
{
int i;
FILE fp=fopen(PATH,"w");
for(i=0;i<n;++i)
scanf("%ld %s %d %c %s %s",&stu[i].num,stu[i].name,&stu[i].age,&stu[i].sex
,stu[i].speciality,stu[i].address);
fclose(fp);
}
void WritetoFile(long minnum,long maxnum)
{
int i;
FILE fp=fopen(PATH,"r");
for(i=minnum;i<=maxnum;++i)
printf("%ld %s %d %c %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex
,stu[i].speciality,stu[i].address);
fclose(fp);
}
int main()
{
int max,min;
WritetoFile(a,N);
scanf("%d%d",&min,&max);
ReadfromFile(min,max);
return 0;
}