可以在fopen后,用fseek把位置指针移到文件尾,再用ftell获得这时位置指针距文件头的字节数,
这个字节数就是文件的长度.
#include <stdio.h>
main()
{
FILE *fp;
int length;
fp=fopen("c://test.txt","rb"); /* 假设text.txt已在你的c:/下 */
if(fp!=NULL)
{
fseek(fp,0L,SEEK_END);
length=ftell(fp);
fclose(fp);
}
printf("Text.txt文件件的长度是%d bytes", length);
}