编程基本功——计算文件的大小

一、分析

    巧妙利用fseek()重定位流上的文件指针和ftell()获得当前文件指针相对于文件开头处的位置,可以高效率求的文件的大小

二、源码

   1: #include "stdio.h"
   2:  
   3: int main()
   4: {
   5:     FILE *fp;
   6:     long f;
   7:     fp = fopen("C:\\test.txt", "r");
   8:     fseek(fp, 0, SEEK_END);
   9:     f = ftell(fp);
  10:     fclose(fp);
  11:     printf("the length of the file is %d bytes\n", f);
  12:     return 0;
  13: }
原文地址:https://www.cnblogs.com/steven_oyj/p/1742511.html