有以下程序#include “stdio.h”int main (void){FILE *fp;int i,a[6]={1,2,3,4,5,6k};fp=fopen(“d3.dat”,"w+b");fwrite(a,sizeof(int),6,fp);fseek(fp,sizeof(int)*3,SEEK_SET);/*该语句使读文件的位置指针从文件头向后移动3个int型数据*/ fread(a,sizeof(int),3,fp);fclose(fp);for(i=0;<6;i++)printf("%d"a[i]);return 0;}程序运行结果是
A. 4,5,6,4,5,6,
B. 1,2,3,4,5,6,
C. 4,5,6,1,2,3,
D. 6,5,4,3,2,1,
查看答案
有以下程序#include “stdio.h”int main(void){FILE *fp; int k,n,a[6]={1,2,3,4,5,6};fp=fopen(“d2.dat”,”w”);fprintf(fp,”%d%d\n”,a[0],a[1],a[2]);fprintf(fp, “%d%d%d \n”,a[3],a[4],a[5]);fclose(fp);fp=fopen("d2.dat”,"r");fscanf(fp, "%d%d",&k,&n);printf("%d%d\n",k,n);fclose(fp);return 0;}程序的运行结果是
A. 12
B. 1
C. 1234
D. 123456
有以下程序(提示:程序中fseek(fp,-2L*sizeof(int),SEEK_END;语句的作用是使位置指针从文件末尾向前移2*sizeof(int)字节)# include "stdio.h"int main(void){FILE*fp;int i,a[4]={1,2,3,4},b;fp=fopen("data.dat","wb");for(i=0;i<4;i++)fwrite(&a[i],sizeof(int),1,fp);fclose(fp);fp=fopen("data.dat","rb");fseek(fp,-2L*sizeof(int),SEEK_END) ;fread(&b,sizeof(int),1,fp);/*从文件中读取sizeof(int)字节的数据到变量b中*/fclose(fp);printf("%d\n",b) ;return 0;}执行后输出结果是
A. 2
B. 1
C. 4
D. 3
有如下程序#include "stdio.h"int main(void){FILE *fp1;fp1=fopen("f1.txt","w");fprintf(fp1,"abc");fclose(fp1);return 0;}若文本文件f1.txt中原有内容为:good,则运行以上程序后文件f1.txt中的内容为
A. goodabc
B. abcd
C. abc
D. abcgood
有以下程序#include "stdio.h"void WriteStr(char *fn,char *str){ FILE *fp;fp=fopen(fn,"w");fputs(str,fp);fclose(fp);}int main(void){WriteStr("t1.dat","start");WriteStr("t1.dat","end");return 0;}程序运行后,文件t1.dat中的内容是_____。
A. start
B. end
C. startend
D. endrt