title: How to print contents of buffer in C?
body: <p>C newbie here working on problem set 4 of CS50, where you are given a memory card to recover 50 jpeg files.</p>
  
  <p>I'm trying to read the raw data 512 bytes at a time, but I would like to know how to I can print the contents of each 512 byte block ?</p>
  
  <p>My method of using <code>fwrite</code> doesn't seem to be printing anything in this instance:</p>
  
  <pre><code>fread(buffer, 512, 1, inptr);
  
  fwrite(buffer, 1, 512, stdout);
  </code></pre>
  
  <p>Rest of code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  
  int main(int argc, char *argv[])
  {
      // Ensure only 1 command-line argument
      if (argc != 2)
      {
          fprintf(stderr, "Usage: ./recover infile");
          return 1;
      }
  
      // Remember filename
      char *infile = argv[1];
  
  
      // Open input file
      FILE *inptr = fopen(infile, "r");
      if (inptr == NULL)
      {
          fprintf(stderr, "Could not open %s.\n", infile);
          return 2;
      }
  
      // Create buffer to store 8 bits 512 times
      uint8_t buffer[512];
  
      fread(buffer, 512, 1, inptr);
  
      fwrite(buffer, 1, 512, stdout);
  
      // Close infile
      fclose(inptr);
  
      return 0;
  }
  </code></pre>