#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语言代码)格式错误!!!浏览:964 |
求组合数 (C语言代码)浏览:834 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1238 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:395 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:463 |
字符串比较 (C语言代码)浏览:539 |
敲七 (C语言代码)浏览:2234 |
母牛的故事 (C语言代码)浏览:445 |
生日日数 (C语言代码)浏览:856 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:767 |