这个代码用来计算文件长度有什么问题啊为什么会是输出-1呢?
#include <stdlib.h>
long filesize( FILE *fp)
{
long cur_pos,length;
cur_pos = ftell(fp);
fseek(fp,0,SEEK_END);
length=ftell(fp);
fseek(fp,cur_pos,SEEK_SET);
return length;
}
void main(int argc, char *argv[])
{
FILE *fp;
char Name[20];
fp=fopen("test.txt","rb");
fgets(Name,20,fp);
printf("file length is %ld.\n",filesize(fp));
fgets(Name,20,fp);
fclose(fp);
}