以下程序是把文件file1.dat中的内容复制到一个名为file2.dat新的文件中,请补全程序。#includevoidmain(){FILE*fpr,*fpw;if((fpr=fopen("file1.dat","rb"))==NULL)exit(0);if((fpw=fopen(________________,"wb"))==NULL)exit(1);while(!feof(fpr))fputc(_________________,fpw);fclose(fpr);fclose(fpw);}
举一反三
- 以下程序的功能是将文件exam1.c的内容复制到exam2.c中,请填空。 #include<stdio.h> main() { FILE *fp,*fp; fp1=fopen(___①___); fp2=fopen(___②___); while(!feof(fp1)) fputc(__③___); fclose(fp1); fclose(fp2); }
- 以下程序的功能是将文件file.c的内容输出到屏幕上并复制到文件file2.c中。请填空。int main (void){ FILE *fp1,*fp2; fp1=fopen("file1.c","r"); fp2=fopen("file2.c","w"); while(!feof(fp1)) putchar(fgetc(fp1)); ____; while(!feof(fp1)) fputc(____); fclose(fp1); fclose(fp2); return 0;}
- 下面程序把从终端读入的文本(用@作为文本结束标志)输出到一个名为bi.dat的新文件中。请填空。 #include "stdio.h" FILE *fp; { char ch; if( (fp=fopen ( 【 】 ) )= = NULL)exit(0); while( (ch=getchar( )) !='@') fputc (ch,fp); fclose(fp); }
- 阅读以下程序,对程序功能的描述中正确的是 #icnlude int main() { FILE *in, *out; char ch, infile[10], outfile[10]; printf("Enter the infile name:"); scanf("%s", infile); printf("Enter the outfile name:"); scanf("%s", outfile); if ((in = fopen(infile, "r")) == NULL) { printf("cannot open infile."); exit(0); } if ((out = fopen(outfile, "w")) == NULL) { printf("cannot open outfile."); exit(0); } while (!feof(in)) { fputc(fgetc(in), out); } fclose(in); fclose(out); return 0; }
- 下面的程序用变量count统计文件中小写字母的个数。 #include #include int main(void) { FILE *fp; char a; int count=0; if((fp=fopen("d:letter.txt",【 】))==NULL) { printf("can not open file "); exit(0);} while(!feof(fp)) { 【 】 if(【 】) count++; } fclose(fp); printf("字符个数是:%d ",count); return 0; } 【】中应依次填入( )。