title: Conversion from binary file to hex in C
body: <p>I am trying to write some simple program to uploading files to my server. I' d like to convert binary files to hex. I have written something, but it does not work properly.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  static int bufferSize = 1024;
  FILE *source;
  FILE *dest;
  
  int n;
  int counter;
  
  int main() {
      unsigned char buffer[bufferSize];
      source = fopen("server.pdf", "rb");
      if (source) {
          dest = fopen("file_test", "wb");
  
          while (!feof(source)) {
              n = fread(buffer, 1, bufferSize, source);
              counter += n;
              strtol(buffer, NULL, 2);
              fwrite(buffer, 1, n, dest);
          }
      }
      else {
          printf("Error");
      }
      fclose(source);
      fclose(dest);
  }
  </code></pre>
  
  <p>I use <a href="http://www.cplusplus.com/reference/cstdlib/strtol/" rel="nofollow">strtol</a> to convert binary do hex. After invoking this code I have still strange characters in my file_test file.</p>
  
  <p>I' d like to upload a file on server, for example a <a href="http://en.wikipedia.org/wiki/Portable_Document_Format" rel="nofollow">PDF</a> file. But firstly I have to write a program, that will convert this file to a hex file. I'd like that the length of a line in hex file would be equal 1024. After that, I will upload this file line by line with <a href="http://en.wikipedia.org/wiki/PL/SQL" rel="nofollow">PL/SQL</a>.</p>