title: Read a file in buffer then write buffer in new file
body: <p>I am kind of new to filing operations used in C. I want to read a file, copy its content to a buffer, and then copy the contents from that buffer to a new file. (The purpose is for usage of this buffer in another task)
  I am using the code below for reading my file in a buffer</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main () 
  {
      FILE * fileP;
      long size;
      char * buffer;
      size_t final;
  
      fileP= fopen ( "C:\\Users\\test.pdf" , "rb" );
      if (fileP==NULL) {fputs ("File error",stderr); 
      exit (1);
      }
  
      // calculating file size
      fseek (fileP, 0 , SEEK_END);
      size = ftell (fileP);
      rewind (fileP);
  
      // allocating mem for file
      buffer = (char*) malloc (sizeof(char)*size);
      if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
  
      // copying file into buffer
      final = fread (buffer,1,size,fileP);
      if (final != size) 
      {
          fputs ("Reading error",stderr); 
          exit (3);
      }
      // the whole file is now loaded in the memory buffer. 
  
      fclose (fileP);
      free (buffer);
      return 0;
  }
  </code></pre>
  
  <p>I know I need to use fwrite for writing the contents of buffer in to a new file, but I can't seem to get which parameters would be written in it. Or is there any better solution for it?</p>