阅读以下程序及对程序功能的描述,其中正确的是 #include <stdio.h> main() {FILE *in,*out
阅读以下程序及对程序功能的描述,其中正确的是
#include <stdio.h>
main()
{ FILE *in,*out;
char ch,infile[10],outfile[10];
printf("Enter the infile name:\n");
scanf("%s",infile);
printf("Enter the outfile name: \n");
scanf("%s",outfile);
if((in=fopen(infile,"r"))==NULL)
{ printf("cannot open infile\n");
exit(0); }
if((out=fopen(outfile,"w"))==NULL)
{ printf("cannot open outfile\n");
exit(0); }
while(! feof(in))fputc(fgetc(in),out);
fclose(in);fclose(out); }
A.程序完成将磁盘文件的信息在屏幕上显示的功能
B.程序完成将两个磁盘文件合二为一的功能
C.程序完成将一个磁盘文件复制到另一个磁盘文件中
D.程序完成将两个磁盘文件合并并在屏幕上输出
解析:本题中,最主要的是掌握几个有关文件的函数的应用。
函数名:fopen
功能:打开一个文件
调用方式FILE *fp ;fp=fopen(文件名,使用文件方式);
函数名:feof
功能:检查文件是否结束
调用方式:feof(FILE *fp);
函数名:fputc
功能:把一个字符写到磁盘文件上去
调用方式:fputc(ch,fp)(ch是要输出的字符,fp是从指定的文件读入一个字符,该文件必须是以读或读写方式打开的 调用方式:ch=fgetc(fp)(ch是字符变量,fp是文件指针变量);
函数名:fclose
功能:关闭一个文件
调用方式:fclose(文件指针)。