第七章测试1.
如果二进制文件a.dat已经存在,现在要求写入全新数据,应以()方式打开。
A: B:"wb+" C:"w" D:"w+"
答案:A
2.
若fopen()函数打开文件失败,其返回值是( )。
A:1 B:ERROR C:NULL D:-1 3.
若读文件还未读到文件末尾, feof()函数的返回值是( )。
A:1 B:非0 C:-1 D:0 4.
fputc(ch,fp) 把一个字符ch写到fp所指示的磁盘文件中,若写文件失败则函数的返回值为( )。
A:0 B:非0 C:EOF D:1 5.
阅读以下程序,对程序功能的描述中正确的是()
#icnlude <stdio.h>
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;
}
A:
程序完成将两个磁盘文件合二为一的功能。
B:程序完成将两个磁盘文件合并并在屏幕上输出的功能。
C:程序完成将磁盘文件的信息在屏幕上显示的功能。
D:程序完成将一个磁盘文件中的信息复制到另一个磁盘文件中的功能。