feof(fp)函数用来判断文件是否结束,如果遇到文件结束,函数值为_______,否则为_______。
查看答案
以下程序由终端输入一个文件名,然后把从终端键盘输入的字符依次存放到该文件中,用#作为结束输入的标志。请填空。#include void main(){FILE * fp;char ch,fname[10];printf("lnput the name of file\n");gets(fname);if((fp= )==NULL){ printf("Cannot open\n"); exit(0);}printf("Enter data\n");while((ch=getchar())!='#')fputc( ,fp);fclose(fp);}
下面程序用变量count统计文件中字符的个数,请填入适当内容。#include void main(){FILE *fp; long count=0;if((fp=fopen(“letter.dat”,_____))==NULL){printf(“cannot open file \n”);exit(0);}while(fgetc(fp)!=EOF)_____;frintf(“count=%ld\n”,count);fclose(fp);}
下面程序由终端键盘输入字符,存放到文件中,用!结束输入,请填入适当的内容。#include #includevoid main(){FILE *fp;char ch,fname[10];printf("input name of file\n");gets(fname);if((fp=fopen(fname,"w"))==NULL){printf("cannotopen\n");exit(0);}printf("enter data:\n");while( !='!')fputc( );fclose(fp);}
下面程序从一个二进制文件中读入结构体数据,并把结构体数据显示在终端屏幕上。请填入适当内容。#includestruct rec{int num;float total;};void main(){FILE *f;If((f=fopen(“bin.dat”, “rb”))==NULL);{printf(“cannotopen\n”);exit(0);}reout(f);fclose(f);}void reout(_______){struct rec, r;fread(&r,_______,1,f);while(!feof(f)){printf(“%df,%f\n”,_______);fread( ,_______,1,f);}}