int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
先将文件按定位到末尾,然后ftell函数返回当前读写位置
#include <stdio.h>
int main(int argc, char** argv)
{
if (argc < 2)
{
printf("please input the file name.\n");
}
FILE* fp = fopen(argv[1], "r");
if ( NULL == fp)
{
printf("file open error")
return 0;
}
if ( fseek(fp, 0, SEEK_SET) == -1)
{
printf("fseek error!");
}
if ( fseek(fp, 0, SEEK_END) == -1)
{
printf("fseek error!");
}
long size = ftell(fp);
printf("athe file size %ld\n", size);
return 0;
}