title: C - Read file byte by byte using fread
body: <p>I am trying to read a file byte by byte (this is important because I have to measure performance). I can't seem to get the fread to work properly. Right now it just gives me the last byte of the file. </p>
  
  <p>This is what I have: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char **argv) { 
      FILE *fileptr;
      char *buffer;
      long filelen;
      int i;
  
      fileptr = fopen(argv[1], "rb");         
      fseek(fileptr, 0, SEEK_END);          
      filelen = ftell(fileptr);            
      rewind(fileptr);                      
      buffer = (char *)malloc((filelen+1)*sizeof(char)); 
  
      for(i = 0; i &lt; filelen; i++) {
         fread(*&amp;buffer, 1, 1, fileptr); 
      }
  
      printf("File len: %ld\n", filelen);
      printf("%s\n",*&amp;buffer);
  
      fclose(fileptr); // Close the file
  
      return 0;
  }
  </code></pre>
  
  <p>Any help is appreciated</p>