在调用fread fwrite之后,文件指针,会根据读写的长度,相应的往后偏移:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
char *tmp = "hhhh";
FILE *p = fopen("aa.txt", "r+");
char *buf = (char *)malloc(128);
fread(buf, 1, 8, p);
free(buf);
printf("FILE p offset:%d\n", (int)ftell(p));
fwrite(tmp, 1, 4, p );
printf("FILE p offset:%d\n", (int)ftell(p));
fclose(p);
return 0;
}
在调用fread之后,文件指针偏移了8个字节,fwrite之后,又偏移了4个字节