title: Can i use fgetc() or fputc() in a binary file?
body: <p>I am creating an archive program in C, and i want it to save files i provide, list and extract them. <br>
  I had many issues because i used a text file for saving, and it is not the best choice if i want to process binary files like music or photos, because when i extract them, they are not executed correctly (they are corrupted).
  In order to solve this problem, i wanted to create a binary archive file.</p>
  
  <p>Code for file writing (on extraction) is the following: </p>
  
  <pre><code>void scriviFile(const char * arrivo)                                //scrive i file creati in precedenza
  {
      FILE * partenza;
      FILE * target;
      int c;
      int spazio = 'a';
      int i = 0;
      int pos;
      char * path;
      path = collegaSlash(getcwd(NULL, 0), nome);
      partenza = fopen(path, "rb");
      fseek(partenza, inizio, SEEK_SET);
      target = fopen(arrivo, "wb");                                           //apro il file
      if (target) {                                                               //se è aperto
          while ((c = fgetc(partenza)) != EOF &amp;&amp; ftell(partenza)&lt;=fine-10) {                                  //e il carattere preso non eccede la fine del file
              fputc(c, target);
              fputc(c, stdout);
              pos = ftell(partenza);
              if(pos==fine)
              {
                  break;
              }
                                                                              //scrivo lo stesso carattere in out (file in uscita)
          }                                                                   //
  
          fclose(target);                                                     //chiudo il file
          fclose(partenza);
      } 
      else 
      {
          printf("errore di scrittura del file \n");
      }
  
  }
  </code></pre>
  
  <p>Since i need binary files to be extracted correctly, can i use code i wrote above, or do i have to change all <code>fgetc()</code> and <code>fputc()</code> functions with <code>fread()</code> and <code>fwrite()</code>?<br></p>
  
  <p>Thanks</p>