ANSI C实现文件长度读取
#include <stdio.h>long fsize(FILE *fp)
{
long cur, size;
cur = ftell(fp);
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, cur, SEEK_SET);
return size;
}
int main(void)
{
FILE *fp;
fp = fopen("test.c","r");
printf("size = %ldn", fsize(fp));
fclose(fp);
getchar();
return 0;
}
没有评论:
发表评论