1. 程式人生 > >通過檔案指標來獲取檔案的大小(fseek與ftell函式 )

通過檔案指標來獲取檔案的大小(fseek與ftell函式 )

#include <stdio.h>

main()

{

   FILE *fp;

   char filename[80];

   long length;

   printf("輸入檔名:");

   gets(filename);

   //以二進位制讀檔案方式開啟檔案

   fp=fopen(filename,"rb");

   if(fp==NULL)

      printf("file not found!\n");

   else

      {

         //把檔案的位置指標移到檔案尾

          fseek(fp,OL,SEEK_END);

         //獲取檔案長度;

          length=ftell(fp);

          printf("該檔案的長度為%1d位元組\n",length);

          fclose(fp);

      } }