函数介绍:
long ftell(文件指针)用于得到文件指针当前位置,返回相对于文件首的位移量,一般结合 fseek 函数一起使用。
简例:
#include "stdafx.h"
#include "stdio.h"
#include "process.h"
int main(int argc, char* argv[])
{
//get length of the file
FILE * fp;
if ((fp = fopen("test.txt","r")) == NULL)
{
printf("Open fail!\n");
exit(0);
}
fseek(fp,0L,2); // set fp to end of file
long nLen = ftell(fp);
printf("The length of the file is %d!\n",nLen);
return 0;
}