title: Copying all file contents into a char array with fread
body: <p>I'm trying to copy the contents of a file, specifically a PDF file into a character array so that I can send it over the network.</p>
  
  <p>I'm using the fopen with fread for this.</p>
  
  <pre><code>//Get the file path
  getFilePath();
  //Open the file
  fopen_s(&amp;fp, filePath, "r");
  fseek(fp, 0, SEEK_END);
  size = ftell(fp);
  rewind(fp);
  //allocate memory
  buffer = (char*)malloc(sizeof(char)*size);
  
  int charsTransferred = fread(buffer, 1, size, fp);
  
  fclose(fp);
  free(buffer);
  </code></pre>
  
  <p>I have charsTransferred to see how many characters were transferred over by fread. Using size I can tell how many characters should have been moved over, but obviously I'm not getting that many back. Does anyone know what the issue here could be?</p>