正在加载图片...
例: float a20 第13章第4节 fp- fopen(“ filel. dat”,“wb”); for(i=0;i<20;i++) 将数组中的各元素al[l依次写入文件 fwrite(&ai, 4, 1, fp) filel. dat中 返回值「tead0}→今「成功:cout值 write 不成功:0 习题:P327136有5个学生,每个学生有3门课的成绩,从输盘上输入以上数据(姓名, 学号,三门课成绩,计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件中 解: include stdio. h't main struct student Sint no char na 301 it sc 3; float ave }s3; FILE *fp Int 1,j; if((fp=fopen("a: filel. txt","wb")==NULL) Printf("n can not open the filen); exit(0);float a[20] ...... fp=fopen(“file1.dat”, “wb”); for(i=0; i<20; i++) fwrite(&a[i], 4, 1, fp); ...... 例: 将数组中的各元素a[i],依次写入文件 file1.dat中 习题:P327 13.6 有5个学生, 每个学生有3门课的成绩, 从输盘上输入以上数据(姓名, 学号,三门课成绩), 计算出平均成绩, 将原有数据和计算出的平均分数存放在磁盘文件中. 解: # include "stdio.h" main() {struct student {int no; char na[30]; int sc[3]; float ave; } s[3]; FILE *fp; int i,j; if((fp=fopen("a:\\file1.txt","wb"))==NULL) {printf("\n can not open the file\n"); exit(0);} 返回值 fread() fwrite() 成功: count 值 不成功: 0 第13章第4节
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有