有以下程序(提示:程序中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;}执行后输出结果是
查看答案
有如下程序#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
有以下程序#include "stdio.h"int main(void){ 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);return 0;}程序运行后的输出结果是
A. 0 0
B. 123 45
C. 1 4
D. 1 2
有以下程序#include "stdio.h"int main(void){ FILE *fp; int i,k=0,n=0;fp=fopen("d1.dat","w");for(i=1;i<4;i++) fprintf(fp,”%d”,i);fclose(fp);fp=fopen("d1.dat","r");fscanf(fp,"%d%d",&k,&n);printf("%d %d\n",k,n);fclose(fp);return 0;}执行后输出结果是
A. 1 2
B. 123 0
C. 1 23
D. 0 0