Rowson


私信TA

用户名:RowsonYong

访问量:5431

签 名:

等  级
排  名 24283
经  验 567
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校 Soc
专  业

  自我简介:

TA的其他文章

#include<stdio.h>
typedef struct Stu{
    char StuNo[8];
    char Name[20];
    float iScore[3];
}Student;
void main()
{
    FILE *fp;  
    Student stu[2];
    float AveScore=0;
    int i;
    printf("Please input the students' data...\n");
    printf("Stu.No.        Name        Score1        Score2        Score3\n");
    scanf("%s%s",stu[0].StuNo,stu[0].Name);
    for(i=0;i<3;i++)
    {
        scanf("%f",&stu[0].iScore[i]); 
        AveScore+=stu[0].iScore[i];
    }
    AveScore=AveScore/3; //好的方法是将平均值也放入结构体
    fp=fopen("stud.dat","rb+");
    fwrite(&stu[0],sizeof(Student),1,fp);//因为fwrite写入的为二进制文件,用记事本看是乱码
    rewind(fp);
    fread(&stu[1],sizeof(Student),1,fp);
    printf("%s %s %.1f %.1f %.1f\n",stu[1].StuNo,stu[1].Name,stu[1].iScore[0],stu[1].iScore[1],stu[1].iScore[2]);
    fclose(fp); 
}


 

0.0分

0 人评分

  评论区