执行以下程序后, test.txt 文件的内容是 ( 若文件能正常打开 )#include main(){ FILE *fp;char *s1=Fortran,*s2=Basi

7 查阅

执行以下程序后, test.txt 文件的内容是 ( 若文件能正常打开 )

#include

main()

{ FILE *fp;

char *s1="Fortran",*s2="Basic";

if((fp=fopen("test.txt","wb ” ))==NULL)

{ printf("Can't open test.txt file\n");exit(1);}

fwrite(s1,7,1,fp); /* 把从地址 s1 开始的 7 个字符写到 fp 所指文件中 */

fseek(fp,0L,SEEK_SET); /* 文件位置指针移到文件开头 */

fwrite(s2,5,1,fp);

fclose(fp);

}

A)Basican

B)BasicFortran

C)Basic

D)FortranBasic

参考答案:

A(43)A) 解析 : 第一 次 fwrit e 操作 把 Fortra n 写到文 件 f p 中 , 第二次操作 , 把 Basi c 写入文 件 f p 中 ,此时把 Fortr 字符覆盖了 , 所以最后输出的是 Basican 。

计算机二级