fseek函数的用法
======================================================================== ======================================================================== ======================================================================== 原文: http://www./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 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 调用形式:
其中,“位移量”是long型数据,它表示位置指针相对于“起始点”移动的字节数。如果位移量是一个正数,表示从“起始点”开始往文件尾方向移动;如果位移量是一个负数,则表示从“起始点”开始往文件头方向移动。 “起始点”不能任意设定,它只能是在stdio.h中定义的三个符号常量之一:
例如: fseek(fp,50L,0);或fseek(fp,50L,SEEK_SET); 其作用是将位置指针移到离文件头50个字节处。 |
|