fp = fopen(filename,"rb");
if( fp==0 ){
printf("Can't open this file for reading: %s\n", filename);
return;
}
fseek(fp,0,2); // 将fp指向文件的末尾
filesize = ftell(fp); // 计算fp相对于文件头的偏移字节数
rewind(fp); // 将fp重新指向文件的开头
fseek()函数解释
int fseek(FILE *stream, long offset, int fromwhere);
fromwhere
- 0(SEEK_SET) :: 文件头
- 1(SEEK_CUR) :: 当前位置
- 2(SEEK_END) :: 文件尾
offset
- 以fromwhere为基准的偏移量,单位是字节
返回值
- 成功,返回0,失败返回非0值。