g num=0;
if(( fp=fopen("fname.dat","r"))==NULL)
{ printf( "Can’t open file! \n"); exit(0);}
while 【17】
{ fgetc(fp); num++;}
printf("num=%d\n", num);
fclose(fp);
}
(12)以下C语言程序将磁盘中的一个文件复制到另一个文件中,两个文件名在命令行中给出。
#include
main(int argc, char *argv)
{ FILE *f1,*f2; char ch;
if(argc< 【18】 )
{ printf("Parameters missing!\n"); exit(0); }
if( ((f1=fopen(argv[1],"r")) = = NULL)||((f2=fopen(argv[2],"w")) = = NULL))
{ printf("Can not open file!\n"); exit(0);}
while( 【19】 )fputc(fgetc(f1),f2);
fclose(f1); fclose(f2); }
答案:
一、选择题:
01) C 02) D 03) D 04) B 05) C
06) B 07) D 08) A 09) D 10) D
11) A 12) A 13) D 14) B 15) A
16) C 17) A 18) B
二、填空题:
(1) Hell
(2) “d1.dat”,”rb”或 “d1.dat”,”r+b”或”d1.dat”,”rb+”
(3) !feof(fp)
(4) fopen
(5) “bi.dat”,“w”或“bi.dat”,“wt”或“bi.dat”,“w+t”
(6) fname
(7) fp
(8) "bi.dat"
(9) fp
(10) "w"或"w+"或"wt"或"w+t"或"""wt+"
(11) str[i]-32 或str[i]-(’a’-’A’或str[i]-’a’+’A’
(12) "r"或"r+"或"r+t"或"rt+"
(13) "bi.dat","w"
(14) fclose(fp)
(15) fopen(fname,"w")
(16) ch
(17) (!feof(fp))
(18) 3
(19) !feof(f1)
[ 结 束 ]
责任编辑:小草