簡體   English   中英

將 Int 寫入 C 中的文件

[英]Writing an Int to a file in C

以下代碼不起作用。表示 fprint 未格式化。 任何幫助將不勝感激,請勿將此鏈接到已發布的帖子。 沒有一個。 我找不到一種方法來寫入文件。 它是一個整數。

   void print(int number, int readpfd)
    {

      FILE *out1;
      out1 = fopen("outfile.txt","w");

      int i;
      int f;

      char file_name[42];
      char cover[42];

      for( i = 0; i < number; i++ )
      {
         read(readpfd, &f, sizeof(int));
         fprintf("out1, %d\n", f);   //this is the line that wrong
      }
      close(readpfd);
      fclose(out1);
  }

這是基本的語法錯誤。 您可以隨時參考手冊頁。 用這個替換你的fprintf語句。

fprintf(out1, "%d", f);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM