title: Reading binary file to unsigned char array and write it to another
body: <p>Hello, I have some problem with rewriting files using C++. I try to read data from one binary file and write it to another. </p>
  
  <pre><code>{
      // Reading size of file
      FILE * file = fopen("input.txt", "r+");
      if (file == NULL) return;
      fseek(file, 0, SEEK_END);
      long int size = ftell(file);
      fclose(file);
      // Reading data to array of unsigned chars
      file = fopen("input.txt", "r+");
      unsigned char * in = (unsigned char *) malloc(size);
      for (int i = 0; i &lt; size; i++)
          in[i] = fgetc(file);
      fclose(file);
  
      file = fopen("output.txt", "w+");
      for (int i = 0; i &lt; size; i++)
          fputc((int)in[i], file);
      fclose(file);
      free(in);
  }
  </code></pre>
  
  <p>But it write my buffer and also append some 0xFF bytes to the end of file (it append some bytes for small files, but can append some kilobytes for greater files). In what can be problem?</p>