怎么使用fseek?
怎么使用fseek啊?
在使用fseek(fp,1000,1,0);
怎么老是出现错误?
难道在VC下不能使用FSEEK了吗?
谢谢!
[解决办法]
fseek怎么会有四个参数呢
[解决办法]
int fseek( FILE *stream, long offset, int origin );
Example
/* FSEEK.C: This program opens the file FSEEK.OUT and
* moves the pointer to the file 's beginning.
*/
#include <stdio.h>
void main( void )
{
FILE *stream;
char line[81];
int result;
stream = fopen( "fseek.out ", "w+ " );
if( stream == NULL )
printf( "The file fseek.out was not opened\n " );
else
{
fprintf( stream, "The fseek begins here: "
"This is the file 'fseek.out '.\n " );
result = fseek( stream, 23L, SEEK_SET);
if( result )
perror( "Fseek failed " );
else
{
printf( "File pointer is set to middle of first line.\n " );
fgets( line, 80, stream );
printf( "%s ", line );
}
fclose( stream );
}
}
[解决办法]
man fseek
[解决办法]
int fseek( FILE *stream, long offset, int origin );
origin=0 文件首
origin=1 当前位置
origin=2 文件尾
offset 为距离的origin 字节数
[解决办法]
你还是装个msdn吧
[解决办法]
函数名: 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参数错误,用法:
#include"stdio.h"
fseek(文件类型指针fp,位移量,起始点);
其中:
起始点 对应的数字 代表的文件位置
SEEK_SET 0 文件开头
SEEK_CUR 1 文件当前位置
SEEK_END 2 文件末尾
[解决办法]
以后需再关注,现在先帮你顶一下
[解决办法]
都是很好的建议! 值得学习