# include <stdio.h>
void main(){
FILE *fp;
int k,n ,a[6]={1,2,3,4,5,6};
fp=fopen("d2.dat","w");
fprintf(fp,"%d %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);
//m=ftell(fp);
printf("此时文件的指针为:");
printf("%ld\n",ftell(fp));
fscanf(fp,"%d %d",&k,&n);
printf("%d %d\n",k,n);
printf("此时文件的指针为:");
printf("%ld\n",ftell(fp));
fscanf(fp,"%d %d",&k,&n);
printf("%d %d\n",k,n);
printf("此时文件的指针为:");
printf("%ld\n",ftell(fp));
fclose(fp);
}
可是运行的结果为:3 8 12 (位移量问题)为什么是3 8 12 呢,第一个为什么成了3了,而第二次位移量怎么成了8了,相差了5,第三个位移量又成了12了,与上一个差了4,不明白,请高手指点!!
谢谢
慕工程0101907
Cats萌萌
相关分类