#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语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:520 |
【数组的距离】 (C语言代码)浏览:728 |
多输入输出练习1 (C语言代码)浏览:1178 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:904 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:919 |
求圆的面积 (C语言代码)浏览:1667 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:632 |
整除问题 (C语言代码)浏览:518 |
字符逆序 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:762 |