#include <stdio.h>
/*
1.rewind(FILE* fp);
2.fseek(FILE* fp,long size,int mode)
size:相对于参照点的偏移字节数
mode:参照位置
SEEK_CUR : 当前位置
SEEK_SET : 开始的位置
SEKK_END: 结束位置
3. ftell(fp) 文件指针移动多个位置
*/
int main()
{
FILE* fp = fopen("1.txt", "w+");
//读不出来内容!
fputs("ILoveyou", fp);
//文件指针写完后,在文件末尾
//rewind(fp); //文件指针回到文件最开始的地方
printf("%d\n", ftell(fp));
fseek(fp,-8L,SEEK_END);
char readStr[1024] = "";
fgets(readStr, 1024, fp);
puts(readStr);
fclose(fp);
return 0;
}
文件指针移动(完整版)
最新推荐文章于 2023-06-05 08:30:00 发布