返回:成功返回0,失败返回-1并设置error变量。
实例:fseek.c
#include<stdio.h>
main()
{
FILE *stream;
long offset;
fpos_t pos;
stream = fopen ("/etc/passwd", "r");
fseek (stream, 5, SEEK_SET) ;
printf ("offset = %d\n", ftell (stream) );
rewind (stream) ;
fgetpos (stream , &pos) ; /* 用 fgetpos () 取得读写位置 */
printf ("offset = %d\n", pos);
pos.__pos = 10 ; /*pos.__pos的下划线是两道短下划线组合在一起*/
fsetpos (stream, &pos); /*用 fgetpos () 设置读写位置 */
printf ("offset = %d\n", ftell (stream) );
fclose (stream) ;
}
运行程序得:
offset = 5
offset = 0
offset = 10
~
原文地址:http://blog.csdn.net/wangjiaweiwei/article/details/43577313