单选题以下程序:#include main(){ FILE *fp; char str[10]; fp=fopen(myfile.dat,w); fputs(abc,fp); fclose(fp); fp=fopen(myfile.dat,a+); fprintf(fp,%d,28); rewind(fp); fscanf(fp,%s,str); puts(str); fclose(fp);}程序运行后的输出结果是(  )。AabcB28cCabc28D因类型不一致而出错

单选题
以下程序:#include main(){ FILE *fp; char str[10]; fp=fopen(myfile.dat,w); fputs(abc,fp); fclose(fp); fp=fopen(myfile.dat,a+); fprintf(fp,%d,28); rewind(fp); fscanf(fp,%s,str); puts(str); fclose(fp);}程序运行后的输出结果是(  )。
A

abc

B

28c

C

abc28

D

因类型不一致而出错


参考解析

解析:
程序一开始以只写方式(“w”)打开文件myfile.dat,此时,若文件不存在,系统将会建立名为myfile.dat的新文件;若文件已存在,将会清空文件内容后从文件头写入字符串"abc",文件关闭后再以附加方式(“a+”)打开可读写文件,此时写入的数据"28"会被加到文件尾,然后把文件指针移到开头位置,再读入整个字符串到str中,最后输出str的值。答案选择C选项。

相关考题:

有以下程序#include stdio.hmain(){ FILE *fp; int a[10]={1,2,3},i,n;fp=fopen("dl.dat","w");for(i=0;i3;i++) fprintf(fp,"%d",a[i]);fprintf(fp,"\n");fclose(fp);fp=fopen("dl.dat","r");fscanf(fp,"%d",n);fclose(fp);printf("%d\n",n);}程序的运行结果是A)12300B) 123C) 1D) 321

有以下程序#include stdio.hmain(){ FILE *fp; int i=20,j=30,k,n;fp=fopen("d1.dat","w");fprintf(fp,"%d\n",i);fprintf(fp,"%d\n",j);fclose(fp);fp=fopen("d1.dat","r");fscanf(fp,"%d%d",k,n); printf("%d %d\n",k,n);fclose(fp);}程序运行后的输出结果是A.20 30B.20 50C.30 50D.30 20

有以下程序includemain(){FILE*fp;inta[10]={1,2,3},i,n;fp=fopen("d1.daf","w");for( 有以下程序 #include <stdio.h> main() {FILE *fp; int a[10]={1,2,3},i,n; fp=fopen("d1.daf","w"); for(i=0;i<3;i++) fprintf(fp,"%d",a[i]); fprintf(fp,"\n"); fclose(fp); fp=fopen("d1.dat","r"); fscanf(fp,"%d",n); fclose(fp);A.12300B.123C.1D.321

有以下程序#include stdio.hmain(){ FILE *fp; int a[10]={1,2,3},i,n;fp=fopen("d1.dat","w");for(i=0;i3;i++) fprintf(fp,"%d",a[i]);fprintf(fp,"\n");fclose(fp);fp=fopen("d1.dat","r");fscanf(fp,"%d",n);fclose(fp);printf("%d\n",n);}程序的运行结果是A.12300B.123C.1D.321

有以下程序: #includestdio.h main( ) {FILE*fp;char str[10]; fp=fopen("myfile,dat",""); {puts("abe",ip);fclose(fp); fp=fopen("myfile.dat","a*"); fprintf(fp,"%d",28); rewind(fp); fscanf(fp,"%S",str);puts(str); fclose(fp); } 程序运行后的输出结果是( )。A.abcB.28cC.abc28D.内类型不一致而出错

有以下程序include void WriteStr(char*fn,char*str){FILE*fp; fp=fopen(fn,"w");fpu 有以下程序 #include <stdio.h> void WriteStr(char *fn, char *str) { FILE *fp; fp=fopen(fn,"w"); fputs(str,fp);fclose(fp); } main() { WriteStr("t1.dat","start"); WriteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是A.startB.endC.startendD.endrt

有以下程序:includevoid WriteStr(char *fn, char *sir){FILE * fP; fP=fopen(fn,"w") 有以下程序: #include<stdio.h> void WriteStr(char *fn, char *sir) { FILE * fP; fP=fopen(fn,"w"); fput6(str,fp); fclose(fp); } main() { WriteStr("t1.dar","start"); WrlteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是( )。A.startB.endC.startendD.endrt

有以下程序 #include void WriteStr(char*fn,char*str) { FILE*fp; fp=fopen(fn,"w");fputs (str,fp);fclose(fp); } main() { WriteStr("t1.dat","start"); WriteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是______。A.startB.endC.startendD.endrt

有以下程序:include main(){FILE*fp;int i,k,n; fp=fopen("data.dar","w+");for(i=1;i 有以下程序: #include <stdio.h> main() { FILE *fp; int i,k,n; fp=fopen("data.dar","w+"); for(i=1;i<6;i++) { fprintf(fp,"%d ",i); if(i%3==0) fprintf(fp,"\n"); } rewind(fp); fscanf(fp,"%d%d",k,n); printf("%d%d\n",k,n); fclose(fp); } 程序运行后的输出结果是( )。A.0 0B.123 45C.1 4D.1 2

有以下程序include main(){FILE *fp;int i=20,j=30,k,n;fp=fopen("d1.dat","w");fprin 有以下程序 #include <stdio.h> main() { FILE *fp; int i=20,j=30,k,n; fp=fopen("d1.dat","w"); fprintf(fp,"%d\n",i);fprintf(fp,"%d\n",j); fclose(fp); fp=fopen("d1.dat", "r"); fp=fscanf(fp,"%d%d",k,n); printf("%d%d\n",k,n); fclose(fp); } 程序运行后的输出结果是A.20 30B.20 50C.30 50D.3020

有以下程序:include main( ){FILE * fp; int i,k,n;fp = fopen( "data. dat" ,"w +" ) 有以下程序:#include <stdlo.h>main( ){ FILE * fp; int i,k,n; fp = fopen( "data. dat" ,"w +" ) for(i = 1 ;i<6;i ++ ) { fprintf(fp."% d",i); if(i%3 ==0)fprintf(fp," \n"); } rewind(fp); fscanf(fp." % d% d" ,k, n) ;printf(" % d%d \n" ,k,n); fclose(fp);A.0 0B.123 45C.1 4D.1

有以下程序: include main() {FILE *fp; int i,k,n; fp=fopen("data 有以下程序: #include <stdio.h> main() {FILE *fp; int i,k,n; fp=fopen("data.dat","w+"); for(i=1;i<6;i++) {fprintf(fp,"%d ",i); if(i%3==0) fprintf(fp,"\n"); } rewind(fp); fscanf(fp,"%d%d",k,n); printf("%d %d\n",k,n); fclose(fp); } 程序运行后的输出结果是 ______。A.0 0B.123 45C.1 4D.1 2

有以下程序:includemain(){FILE*fp;int a[10]={1,2,3},i,n;fp=fopen("d1.dat","w");fo 有以下程序: #include<stdio.h> main() {FILE*fp;int a[10]={1,2,3},i,n; fp=fopen("d1.dat","w"); for(i=0;i<3;i++)fprintf(fp,"%d",a[i]); fprintf(fp,"\n"); fclose(fp); fp=fopen("d1.dat","r"); fscanf(fp,"%d",&n); fclose(fp); printf("%d\n",n); 程序的运行结果是( )。A.12300B.123C.1D.321

有以下程序includevoid WriteStr(char*fn,char*str){FILE*fp; fp=fopen(fn,"w");fputs 有以下程序 #include<stdio.h> void WriteStr(char*fn,char*str) { FILE*fp; fp=fopen(fn,"w");fputs(str,fp);fclose(fp); } main() { writeStr("t1.dat","start"); WriteStr("t1.dat","end"); } 程序运行后,文件t1.dat中的内容是A.startB.endC.startendD.endrt

有以下程序includemain(){FILE*fp;int i=20,j=30,k,n;fp=fopen(“d1.dat”,“w”);fprintf 有以下程序 #include<stdio.h> main() { FILE*fp;int i=20,j=30,k,n; fp=fopen(“d1.dat”,“w”); fprintf(fp,“%d\n”,i);fprintf(fp,“%d\n”,j); fclose(fp); fp=fopen(“d1.dat”,“r”); fscanf(fp,“%d%d”,k,n);printf(“%d%d\n”,k,n); fclose(fp); } 程序运行后的输出结果是A.20 30B.20 50C.30 50D.30 20

有以下程序 include void WriteStr(char*fn,char*str) {FILE*fp; fp=f 有以下程序 #include<stdio.h> void WriteStr(char*fn,char*str) {FILE*fp; fp=fopen(fn"w");fputs(str,fp);fclose(fp); } main() { WriteStr("t1.dat"start"); WriteStr("t1,dat","end"); } 程序运行后,文件t1.dat中的内容是 ______。A.startB.endC.startendD.endrt

有以下程序includemain(){FILE *fp;int i=20,j=30,k,n;fp=fopen("d1.dat","w");fprint 有以下程序 #include<stdio.h> main() {FILE *fp;int i=20,j=30,k,n; fp=fopen("d1.dat","w"); fprintf(fp,"%d\n",i;fprintf(fp,"%d\n",j); fclose(fp); fp=fopen("d1.dat","r"); fscanf(fp,"%d%d",k,n);printf("%d%d\n",k,n); fclose(fp);} 程序运行A.20 30B.20 50C.30 50D.30 20

有以下程序: #includestdio.1l void WriteStr(char*fn.char*str) { FILE*fp; fp=fopen(fn,"w");fputs(str,fp);fclose(fp);} main { WriteStr("tl.dat","start"); WriteStr("t1.dat","end");) 程序运行后,文件t1.dat中的内容是( )。A. startB.endC.startendD.endrt

有以下程序:includestdio.1lvoid WriteStr(char*fn.char*str){ FILE*fp;fp=fopen(fn,stdio.1lvoid WriteStr(char*fn.char*str){ FILE*fp;fp=fopen(fn,w);fputs(str,fp);fclose(fp);}main{ WriteStr(tl.dat,start);WriteStr(t1.dat,end);)程序运行后,文件t1.dat中的内容是( )。A. startB.endC.startendD.endrt

有以下程序#inculde stdio.hmain(){ FILE*Fp;char str[10];Fp=Fopen(“myFile.dat”,”W”);Fputs(“aBc”,Fp);Fclose(Fp);Fp=Fopen(“myFile.dat”,”a+”);FprintFF(Fp,”%d”,28);reWind(Fp);FscanF(Fp,”%s”,str);puts(str);Fclose(Fp);}程序运行后的输出结果是A.aBcB.28cC.aBc28D.因类型不一致而出错

有以下程序: include main( ) { FILE *fp; int i=20,j=50,k,n; fp=fopen("d1.da 有以下程序: #include<stdi0.h> main( ) { FILE *fp; int i=20,j=50,k,n; fp=fopen("d1.dat","W"); fprintf(fp,"%d\n",i);fprintf(fp,"%d\n",j); fclose(fp); fp=fopen("d1.dat","r",); fscanf(fp,"%d%d",&k,&n); printf("%d%d\n",k,n); fclose(fp); } 程序运行后的输出结果是A.20 30B.20 50C.30 50D.30 20

有以下程序:include main(){FLLE *fp;int i=20,j=30,k,n;fp=fopen("d1.dat""w");fprin 有以下程序: #include <stdio.h> main() {FLLE *fp;int i=20,j=30,k,n; fp=fopen("d1.dat""w"); fprintf(fp,"%d\n",i);fprintf(fp,"%d\n",j); fclose(fp); fp=fopen("d1.dar","r"); fp=fscanf(fp,"%d%d",k,n); printf("%d%d\n",k,n); fclose(fp); ) 程序运行后的输出结果是( )。A.20 30B.20 50C.30 50D.30 20

有以下程序includemain(){ FILE *fp;int i=20,j=30,k,n;fp=fopen("d1.dat","w");fprin 有以下程序 #include<stdio.h> main() { FILE *fp;int i=20,j=30,k,n; fp=fopen("d1.dat","w"); fprintf(fp,"%d\n",i);fprintf(fp,"%d\n",j); fclose(fp); fp=fopen("d1.dat","r"); fscanf(fp,"%d%d",k,n;printf("%d%d\n",k,n); fclose(fp);} 程序运行后的输出结果是A.20 30B.20 50C.30 50D.30 20

( 40 )有以下程序#include stdio.hmain (){ FILE *fp;char str[10];fp=fopen ( " myfile.dat " , " w " ) ;fputs ( " abc " ,fp ) ;fclose ( fp ) ;fpfopen ( " myfile.dat:, " a+ " ) ;fprintf ( fp, " %d " ,28 ) ;rewind ( fp ) ;fscanf ( fp, " %s " ,str ) ; puts ( str ) ;fclose ( fp ) ;}程序运行后的输出结果是A ) abcB ) 28cC ) abc28D )因类型不一致而出错

单选题有以下程序:#include main(){ FILE *fp; int a[10]={1,2,3},i,n; fp=fopen(d1.dat,w); for(i=0;i3;i++) fprintf(fp,%d,a[i]); fprintf(fp,); fclose(fp); fp=fopen(d1.dat,r); fscanf(fp,%d,n); fclose(fp); printf(%d,n);}程序的运行结果是(  )。A12300B123C1D321

单选题有以下程序#include main(){ FILE *fp; int k,n,a[6]={1,2,3,4,5,6}; fp=fopen(d2.dat,w); fprintf(fp,%d%d%d,a[0],a[1],a[2]); fprintf(fp,%d%d%d,a[3],a[4],a[5]); fclose(fp); fp=fopen(d2.dat,r); fscanf(fp,%d%d,k,n); printf(%d%d,k,n); fclose(fp);}程序运行后的输出结果是(  )。A123456B14C1234D12

单选题有以下程序:#include main(){ FILE *fp; int i,a[6]={1,2,3,4,5,6},k; fp=fopen(data.dat,w+b); fprintf(fp,%d,a[0]); for(i = 1;i 6;i++) {  rewind(fp);  fprintf(fp,%d,a[i]); } rewind(fp); fscanf(fp,%d,k); fclose(fp); printf(%d,k);}程序运行后的输出结果是(  )。A6B21C123456D654321