title: C - How to handle last part of file if buffer is bigger?
body: <p>isn't it possible to read bytes left in a file that is smaller than buffer size?</p>
  
  <pre><code>char * buffer = (char *)malloc(size);
  FILE * fp = fopen(filename, "rb");
  
  while(fread(buffer, size, 1, fp)){
       // do something
  }
  </code></pre>
  
  <p>Let's assume size is 4 and file size is 17 bytes. I thought fread can handle last operation as well even if bytes left in file is smaller than buffer size, but apparently it just terminates while loop without reading one last byte.</p>
  
  <p>I tried to use lower system call read() but I couldn't read any byte for some reason. </p>
  
  <p>What should I do if fread cannot handle last part of bytes that is smaller than buffer size? </p>