有以下程序#include "stdio.h"int main(void){ 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);return 0;}程序运行结果是
A. 20 30
B. 20 50
C. 30 50
D. 30 20
有以下程序#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