问题
填空题
下面程序由终端键盘输入一个文件名。然后把从终端键盘输入的字符依次存放到该文件中,用#作为结束输入的标志。
#include<stdio.h>
#include
main()
{FILE *fp;
char ch,fname[10];
printf("Please input the file name.\n");
gets(fname);
if((fp=______)==NULL)/*第一空*/
{printf("()pen it error\n");______;}/*第二空*/
else(printf("Enter the content\n");
while((ch=getchar())!=’#’)
______;/*第三空*/
}
fclose(fp);
}
答案
参考答案:fopen(fname,"w")/*第一空。新建一个名字由字符数组fname的元素组成的文件,采用的方式是只读方式*/
解析:exit(0)/*第二空。关闭当前打开的文件结束程序运行*/ fputc(ch,fp)/*第三空。将字符型变量ch的值输出到文件指针fp指向的文件中*/