[求助] 怎么又是乱码啊?
建立3个学生的数据,求平均分数,再将数据输入到磁盘文件.不知道怎么回事,又是乱码?救命啊?#include<stdio.h>
struct tt
{
char name[10];
float score[3];
int num;
float avg;
}boy[3];
main()
{
FILE *fp;
float sum=0;
int i,j;
for(i=0;i<3;i++)
{
printf("please input the %d boy name\n",i);
scanf("%s",&boy[i].name);
printf("\nplease input the %d boy num\n",i);
scanf("%d",&boy[i].num);
for(j=0;j<3;j++)
{
printf("\nplease input the %d boy three of score\n",i);
scanf("%f",&boy[i].score[j]);
sum+=boy[i].score[j];
boy[i].avg=sum/3.0;
}
printf("the sum=%f\n",sum);
printf("the average score is %f\n",boy[i].avg);
sum=0;
boy[i].avg=0;
}
if((fp=fopen("c:\\sf","a"))==NULL)
{
printf("\ncan't open this file\n");
exit(0);
}
for(i=0;i<3;i++)
if(fwrite(&boy[i],sizeof(struct tt),1,fp)!=EOF);
fclose(fp);
system("pause");
}