计算机二级

执行以下程序后,test.txt文件的内容是(若文件能正常打开)______。 #include <stdio.h> 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所指文件中*/ f seek(fp,

题目

执行以下程序后,test.txt文件的内容是(若文件能正常打开)______。 #include <stdio.h> 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所指文件中*/ f seek(fp, 0L,SEEK_SET);/*文件位置指针移到文件开头*/ fwrite(s2,5,1,fp); fclose(fp); }

A.Basican

B.BasicFortran

C.Basic

D.FortranBasic

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

当已存在一个test.txt文件时,执行函数fopen("test.txt","r+")的功能是()。

A.打开test.txt文件,覆盖原有的内容

B.打开test.txt文件,可以读取和写入新的内容

C.打开test.txt文件,只能写入数据,但不能读取数据

D.打开test.txt文件,只能读取原有内容,但不能写数据


打开abc.txt文件,可以读取和写入新的内容

第2题:

以下程序用来判断指定文件是否能正常打开,请填空。 include main() {FILE*fp;if(((fp=fo

以下程序用来判断指定文件是否能正常打开,请填空。

include<stdio.h>

main()

{FILE*fp;

if(((fp=fopen("test.txt","r"))=【 】))

printf("未能打开文件!\n");

else

printf("文件打开成功!\n");

}


正确答案:NULL
NULL 解析:本题主要考查对文件的打开操作,"r"是为读而打开文本文件。当指定这种方式时,对打开的文件只能进行“读”操作,若指定的文件不存在,则会出错;另外一些情况,如企图去读—个不允许读的文件时,也会出错。当文件运行错误时,使用语句“if(((fp=fopen("test.txt","r"=NULL))”来判断。

第3题:

下面的程序执行后,文件test.txt中的内容是______。 include void fun(char *fname,char

下面的程序执行后,文件test.txt中的内容是______。 #include<stdio.h> void fun(char *fname,char *st) { FILE*myf;int i; myf=fopen("test.txt","w"); for(i=0;i<strlen(st);i++) fputc(st[i],myf); fclose(myf); } main() { fun("test","new one"); fun("test","hello,"); }

A.hello,

B.new onehello,

C.new one

D.hello,ne


正确答案:A

第4题:

下面的程序执行后,文件test.txt中的内容是() include void fun(char*

下面的程序执行后,文件test.txt中的内容是 ( ) # include<stdio.h> void fun(char*<fname,char * st) { FILE*myf;int i; myf=fopen(fname,"w"); for(i=0;i<strlen(st);i+ +) fputc(st[i],myf); fclose (myf); } main( ) { fun("test","new word"); fun("test","hello"); }

A.hello

B.new worldhello,

C.new world

D.hello,rld


正确答案:A

第5题:

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

执行以下程序后,test.txt文件的内容是(若文件能正常打开) ( )。#include <stdio.h>#include <stdlib.h>main( ){ FILE * fp; char * s1 = "Fortran" , * s2 = "Basic"; if((fp = fopen( "test. txt" ," wb" )) = = NULL) { prinff( "Can't open test. txt file \n"); exit(1); } fwrite( s1 ,7,1 ,fp); /* 把从地址s1开始到7个字符写到fp所指文件中*/ fseek(fp,OL,SEEK_SET); /*文件位置指针移到文件开头*/ fwrite (s2,5,1,fp); felose (fp);}

A.Basiean

B.BasieFortran

C.Basic

D.FortranBasie


正确答案:A
解析:程序以“只写”方式打开一个名为test.txt的文件,并向该文件写入指针变量s1指向的7个字符"Fortran",执行fseek函数,使文件位置指针移到文件的开头,再次向文件输入指针变量s2指向的5个字符"Basic"这时系统会覆盖原有的内容"Fortr",所以最后test.txt里的内容为:Basican。

第6题:

执行以下程序后,test.txt文件的内容是(若文件能正常打开)( )。includemain(){FILE*fp;c

执行以下程序后,test.txt文件的内容是(若文件能正常打开)( )。 #include<stdio.h> 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

第7题:

以下程序用来判断指定文件是否能正常打开 , 请填空。

#include <stdio.h>

main()

{ FILE *fp;

if(((fp=fopen( " test.txt " , " r " ))== 【 1 3 】 ))

printf(" 未能打开文件 !\n");

else

printf(" 文件打开成功 !\n");

}


正确答案:

第8题:

以下程序用来判断指定文件是否能正常打开,请填空

#include <stdio.h>

main( )

{FILE *fp;

if (((fp=fopen(“test.txt”,”r”))==【13】))

printf(“未能打开文件!\n”);

else

printf(“文件打开成功!\n”);


正确答案:

13NULL

第9题:

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

#include <stdio.h>

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 。