========================================================================
========================================================================
========================================================================
原文: http://www.fzs8.net/C_Function/2007-06-13/c_6093.html
函数名: fseek
功能: 重定位流上的文件指针
用法: int fseek(FILE *stream, long offset, int fromwhere);
程序例:
#include <stdio.h>
long filesize(FILE *stream);
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("Filesize of MYFILE.TXT is %ld bytes/n", filesize(stream));
fclose(stream);
return 0;
}
long filesize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
========================================================================
fseek()函数用法
jenny 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://wyiceshark.blogbus.com/logs/5323034.html

fseek()函数
调用形式:
#include"stdio.h"
fseek(文件类型指针fp,位移量,起始点);
函数功能:把与fp有关的文件位置指针放到一个指定位置。 其中,“位移量”是long型数据,它表示位置指针相对于“起始点”移动的字节数。如果位移量是一个正数,表示从“起始点”开始往文件尾方向移动;如果位移量是一个负数,则表示从“起始点”开始往文件头方向移动。
“起始点”不能任意设定,它只能是在stdio.h中定义的三个符号常量之一:
起始点
对应的数字 代表的文件位置
SEEK_SET
0 文件开头
SEEK_CUR
1 文件当前位置
SEEK_END
2 文件末尾
例如:
fseek(fp,50L,0);或fseek(fp,50L,SEEK_SET);
其作用是将位置指针移到离文件头50个字节处。