#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 人评分
C语言训练-邮票组合问题* (C语言代码)......浏览:644 |
C语言训练-阿姆斯特朗数 (C语言代码)浏览:849 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:653 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:676 |
震宇大神的杀毒软件 (C++代码)浏览:1103 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:567 |
数组输出 (C语言代码)错误???浏览:558 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:548 |
剪刀石头布 (C语言代码)浏览:748 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:817 |