69,369
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int count;
struct student
{
int id;
char name[90];
float score;;
} stu[3],temp;
struct student readfile(void);
int main()
{
for(count=0;count<3;count++)
{
struct student *pst=&stu[count];
stu[count]=readfile();
printf("id is %d\n",stu[count].id);
pst++;
}
return 0;
}
struct student readfile()
{
FILE *fp;
if((fp=fopen("stud.dat","a+"))==NULL)
{
fputs("Can't open stud.dat!",stderr);
exit(1);
}
fscanf(fp,"%d %s %f %f %f %f",&temp.id,&temp.name,&temp.mathscore,&temp.englishscore,&temp.chinesescore,&temp.average);
fclose(fp);
return temp;
}