题目内容

下面程序由终端键盘输入字符,存放到文件中,用!结束输入,请填入适当的内容。#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);}}

下面程序把从终端读入的10个整数以二进制方式写到一个名为bi.dat的新文件中,请填空。#includeFILE *fp;void main(){int i,j;if((fp=fopen( ,"wb"))==NULL)exit(0);for(i=0;i<10; i++){scanf("%d",&j);fwrite(&j,sizeof(int),1, );}fclose(fp);}

以下程序的功能是将C语言源程序文件exam.c中用反斜杠与星号括起来的非嵌套注释删除,然后存入文件exam.out中。请填入适当内容。#includevoid delcomm(FILE *fp1,FILE *fp2){int c,i=0;while((_______)!=EOF)if(c==’\n’)fprintf(fp2,”\n”);elseswitch(i){case(0):if(c==’/’) i=1;elsefprintf(fp2,”%c”,c);break;case(1):if(c==’*’) i=2;else{fprintf(fp2,”%c”,c); i=0;}break;case(2):if(c==’*’)i=3;break;case(3):i=(c==’/’)?_______;break;}}void main(){FILE *fp1,*fp2;fp1=fopen(“exam.c”,”r”);fp2=fopen(“exam.out”,”w”);delcomm(______);fcloseall();}

以下程序的功能是将文件file1.c的内容输出到屏幕上并复制到文件file2.c 中,请填入适当内容。#includevoid main(){FILE_______;char ch;fp1=fopen(“file1.c”,”r”);fp2=fopen(“file2.c”,”w”);while((ch=fgetc(fp1))!=EOF){putchar( );fputc( )}fclose(fp1);fclose(fp2);}

答案查题题库