#include<stdio.h>
void seek();
int main()
{
seek();
return 0;
}
void seek()
{
FILE* fp = fopen("seek.txt", "w+");
if (!fp)
{
perror("file open failed");
return;
}
fputs("hello", fp); //写入之后文件位置指针再文件末尾
//移动文件位置指针
rewind(fp); //直接移动到文件头
fseek(fp, 2, SEEK_SET);
fseek(fp, -5, SEEK_END);
fseek(fp, 2, SEEK_CUR);
long pos = ftell(fp);
printf("pos %ld\n", pos);
char buf[512];
fgets(buf, 512, fp);
puts(buf);
fclose(fp);
}