title: Read and write a buffer of unsigned char to a file in C?
body: <p>The following code writes an array of unsigned char (defined as <code>byte</code>) to a file:</p>
  
  <pre><code>typedef unsigned char byte;
  void ToFile(byte *buffer, size_t len)
  {
      FILE *f = fopen("out.txt", "w");
      if (f == NULL)
      {
          fprintf(stderr, "Error opening file!\n");
          exit(EXIT_FAILURE);
      }
      for (int i = 0; i &lt; len; i++)
      {
          fprintf(f, "%u", buffer[i]);
      }
      fclose(f);
  }
  </code></pre>
  
  <p>How do I read the file back from <code>out.txt</code> into a buffer of <code>byte</code>? The goal is to iterate the buffer <code>byte</code> by <code>byte</code>. Thanks.</p>