函数名: fsetpos
头文件:<stdio.h>
函数原型: int fsetpos(FILE *stream,const fpos_t *pos);
功 能: 用于将文件指针定位在指定的位置上,fsetpos把与stream相联系的文件指针的位置保存在pos所指的地方。
参 数:FILE *stream 要定位的文件流
const fpos_t *pos 类型fpos_t在stdio.h中定义为要定位的指针位 置 typeddf long fpos_t;
返回值:成功 返回0 ,失败 返回非0值。
程序例: 打开文件并获取stream指针位置,将位置输出
#include<stdio.h> #include<string.h> int main(void){ char string[] = "www.dotcpp.com"; fpos_t filepos; FILE *stream = fopen("test.txt", "w+"); fwrite(string, strlen(string), 1, stream); //将字符串写入文件流中 fgetpos(stream, &filepos); //获取文件的指针位置 printf("The file pointer is at byte %ld\n", filepos); fclose(stream); return 0; }
运行结果
The file pointer is at byte 14
本文固定URL:https://www.dotcpp.com/course/515