title: feof() in C file handling
body: <p>I am reading a binary file byte-by-byte,i need determine that whether or not eof has reached.</p>
  
  <p>feof() doesn't works as "eof is set only when a read request for non-existent byte is made". So, I can have my custom check_eof like:</p>
  
  <pre><code>if ( fread(&amp;byte,sizeof(byte),1,fp) != 1) {
      if(feof(fp))
      return true;
  }
  return false;
  </code></pre>
  
  <p>But the problem is, in case when eof is not reached, my file pointer is moved a byte ahead.
  So a solution might be to use <code>ftell()</code> and then <code>fseek()</code> to get it to correct position.</p>
  
  <p>Another solution might be to buffer the byte ahead in some temporary storage.</p>
  
  <p>Any better solutions?</p>