typedef struct student
{
char name[16];
int age;
double math_score;
double chinese_score;
double english_score;
double physics_score;
double chemistry_score;
double bio_score;
}student,*student_p;
student_p create(char w,char a,int b,double c,double d,double e,double f,double g,double h)
{
student_p p=(student_p)malloc(sizeof(student));
if(p=NULL)
{
printf("空间申请失败");
return NULL;
}
w.name[16]="a";
w.age=b;
w.math_score=c;
w.chinese_score=d;
w.english_score=e;
w.physics_score=f;
w.chemistry_score=g;
w.bio_score=h;
return p;
}student,*student_P;
int main(int argc, const char *argv[])
{
char a[5][10]={"aa","bb","cc","ee","ff"};
int b[5]={11,22,44,34,55};
double c,d,e,f,g,h;
student A,B,C,D,E;
char w[5]={'A','B','C','D','E'};
for(int i=0;i<5;i++)
{
printf("输入成绩:");
scanf("%c%lf%lf%lf%lf%lf%lf",&w[i],&c,&d,&e,&f,&g,&h);
create(w[i],a[i],b[i],c,d,e,f,g,h);
}
FILE *fp=fopen("b.txt","w");
if(fp==NULL)
{
printf("文件打开失败");
return 1;
}
for(int i=0;i<5;i++)
{
fprintf(fp,"%c %d %lf %lf %lf %lf %lf %lf",
w[i].name[16],
w[i].age,
w[i].math_score,
w[i].chinese_score,
w[i].english_score,
w[i].physics_score,
w[i].chemistry_score,
w[i].bio_score);
}
char str[100];
while(1)
{
int ch=0;
int vv=fscanf(fp,"%c",&str[ch]);
ch++;
if(vv=EOF)
break;
}
puts(str);
fclose(fp);
return 0;
}
5-6作业
最新推荐文章于 2024-07-07 21:10:32 发布