title: What really is EOF for binary files? Condition? Character?
body: <p>I have managed this far with the knowledge that <code>EOF</code> is a special character inserted automatically at the end of a text file to indicate its end. But I now feel the need for some more clarification on this. I checked on Google and the Wikipedia page for <code>EOF</code> but they couldn't answer the following, and there are no exact Stack Overflow links for this either. So please help me on this:</p>
  
  <ul>
  <li><p>My book says that binary mode files keep track of the end of file from the number of characters present in the directory entry of the file. (In contrast to text files which have a special EOF character to mark the end). So what is the story of <code>EOF</code> in context of binary files? I am confused because in the following program I successfully use <code>!=EOF</code> comparison while reading from an <code>.exe</code> file in binary mode:</p>
  
  <pre><code> #include&lt;stdio.h&gt;
   #include&lt;stdlib.h&gt;
  
   int main()
   {
  
    int ch;   
    FILE *fp1,*fp2;
  
    fp1=fopen("source.exe","rb");
    fp2=fopen("dest.exe","wb");
  
    if(fp1==NULL||fp2==NULL)
    {
    printf("Error opening files");
    exit(-1);
    }
  
    while((ch=getc(fp1))!=EOF)
    putc(ch,fp2);
  
    fclose(fp1);
    fclose(fp2);
  
    }
  </code></pre></li>
  <li><p>Is <code>EOF</code> a special "character" at all? Or is it a <strong>condition</strong> as Wikipedia says, a condition where the computer knows when to return a particular value like <code>-1</code> (<code>EOF</code> on my computer)? Example of such "condition" being when a character-reading function finishes reading all characters present, or when character/string I/O functions encounter an error in reading/writing?</p>
  
  <p>Interestingly, the Stack Overflow tag for <code>EOF</code> blended both those definitions of the  <code>EOF</code>. The tag for <code>EOF</code> said <em>"In programming realm, EOF is a sequence of byte (or a chacracter) which indicates that there are no more contents after this."</em>, while it also said in the "about" section that <em>"End of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream."</em></p></li>
  </ul>
  
  <p>But I have a strong feeling <code>EOF</code> won't be a character as every other function seems to be returning it when it encounters an error during I/O.</p>
  
  <p>It will be really nice of you if you can clear the matter for me.</p>