title: Reading text from binary file like PDF
body: <p>I have a problem with reading binary file in C++. Currently my code is like this:</p>
  
  <pre><code>FILE *s=fopen(source, "rb");
  fseek(s,0,SEEK_END);
  size_file size=ftell(s);
  rewind(s);
  
  char *sbuffer=(char *) malloc(sizeof(char) * size);
  if(sbuffer==NULL){
      fputs("Memory error", stderr);
      exit(2);
  }
  size_t result=fread(sbuffer,1,size,s);
  if(result != size){
      fputs("Reading error",stderr);
      exit(3);
  }
  fclose(s);
  cout&lt;&lt;sbuffer&lt;&lt;endl;
  </code></pre>
  
  <p>However, the characters printed out on the terminal are all random characters instead of what I write in the PDF file. They are like:</p>
  
  <pre><code>% P D F - 1 . 3 
   % ? ? ? ? ? ? ? ? ? ? ? 
   4   0   o b j 
   &lt; &lt;   / L e n g t h   5   0   R   / F i l t e r   / F l a t e D e c o d e   &gt; &gt; 
   s t r e a m 
   x  ? ? ? j ? 0  E ? ? ? k ?  y Q E # ? ? ? m ? &amp; ? ? @  % + ? .     ? ?  ? ? A i  ?     4 z \ 1 G W ? ?  - , ? ? ? (  ? ? ?  9 ? ? ? ? ?  \ ? } ? ? ? e ? ? ? ? 0 ? ? ? ~ ? , ? ? &amp; 8 ? ? x e 4 ? r 
   | ? ? ? 
            ? ? ? ? E  &gt; a ? ? z &amp; ? Z ? &lt; ?  }  '  ? ? ? j p ? ? Q 7 0 ? ? ? S %  - p ? ? ? 7 D  ?  ? ? ' Q z Q ?  ? ? ? ? ? ? ? ? ? \ 2 ? ? 7 ? ? ? &lt; ? ? D ~  ? ? ? 
  
   e n d s t r e a m 
   e n d o b j 
   5   0   o b j 
   2 2 8 
   e n d o b j 
   2   0   o b j
  </code></pre>
  
  <p>And many others characters like the above. I tried to search for a long time but cannot find out how to get the actual characters out for later processing. By the way, I'm trying to write a compressor which takes binary file as input and output. Any help here is highly appreciated!</p>