Cプログラミング
 Computer >> コンピューター >  >> プログラミング >> Cプログラミング

ファイルのサイズを見つけるためのCプログラム


これは、ファイルのサイズを見つけるためのCプログラムです。

アルゴリズム

Begin
   function findfileSize()
   Open a file pointer fp in read only mode.
   If fp is equals to null then
      Print “File not found” and return -1.
   Else count the file size.
      Close the file.
   Put the file pointer at the beginning of the file
   Declare a integer variable result and initialize it with the output of the ftell() function.
   Close file pointer fp.
   Return result.
End

#include <stdio.h>
int findfileSize(char f_n[]) {
   FILE* fp = fopen(f_n, "r"); // opening a file in read mode
   if (fp == NULL) // checking whether the file exists or not {
      printf("File Not Found!\n");
      return -1;
   }
   fseek(fp, 0L, SEEK_END);
   int res = ftell(fp); //counting the size of the file
   fclose(fp); //closing the file
   return res;
}
int main() {
   char f_n[] = { "b.txt" }; //file name is “b.txt” whose size is to be determined
   int result = findfileSize(f_n);
   if (result != -1)
   printf("Size of the file is %ld bytes \n", result); //printing the file size
   return 0;
}

出力

Size of the file is 2649 bytes

  1. C++で二重リンクリストのサイズを見つけるプログラム

    この問題では、二重にリンクされたリストが与えられます。私たちのタスクは、C++で二重リンクリストのサイズを見つけるプログラムを作成することです。 二重リンクリストは特殊なタイプのリンクリストであり、単一リンクリストと比較して、順方向と逆方向の両方の方法で簡単にナビゲーションできます。以下は、二重リンクリストの概念を理解するための重要な用語です。 リンク-リンクリストの各リンクには、要素と呼ばれるデータを格納できます。 次へ-リンクリストの各リンクには、次と呼ばれる次のリンクへのリンクが含まれています。 前-リンクリストの各リンクには、前と呼ばれる前のリンクへのリンクが含ま

  2. Pythonでサイズkのサブリストの最大値を見つけるプログラム

    リスト番号と別の値kがあるとすると、サイズkの各サブリストの最大値を見つける必要があります。 したがって、入力がnums =[12、7、3、9、10、9] k =3の場合、出力は[12、9、10、10]になります。 これを解決するには、次の手順に従います- numsのサイズの場合、 空白のリストを返す res:=新しいリスト temp:=nums [0] temp:=npoint:=0 0からk− 1の範囲のiの場合、実行 tempの場合、 temp:=nums [i] ポイント:=i resの最後にtempを