title: How to read a char array stored in a file, into a char buffer during runtime
body: <p>I'm working in C and I'm modifying existing code.</p>
  
  <p>I have a char array which is stored in a file as follows:</p>
  
  <pre><code>"\x01\x02\x03"
  "\x04\x05\x06"
  "\x07\x08\x09"
  </code></pre>
  
  <p>In the original source code this char array is included as follows:</p>
  
  <pre><code>const static char chs[] =
  #include "file.h"
  ;
  </code></pre>
  
  <p>I'm modifying this code to load the file into a char array during runtime (to get the exact same result as with the above approach) instead of it to be included by the pre-processor. My first approach was to simply read the file into a char buffer, as follows:</p>
  
  <pre><code>FILE *fp;
  const char *filename = "file.h";
  fp = fopen (filename, "rb");
  assert(fp != NULL);
  
  fseek(fp, 0L, SEEK_END);
  long int size = ftell(fp);
  rewind(fp);
  
  // read entire file into the buffer
  char *buffer = (char*)malloc(sizeof(char) * size);
  size_t nrOfBytesRead = fread(buffer, 1, size, fp);
  </code></pre>
  
  <p>However I've quickly discovered that this is not correct. The file already contains the exact code representation of the char array, I cannot simply read it into a char buffer and get the same result as the include approach.</p>
  
  <p>What is the best way to get my char array which is stored in file, into a char array during runtime?</p>