title: CTRL+D (EOF) not detected in trivial program with getchar()?
body: <p>I have the following piece of c code. When I press <kbd>CTRL</kbd>+<kbd>D</kbd> the program does not recognize it as EOF.</p>
  
  <p>Few notes:</p>
  
  <blockquote>
    <p>I am running Ubuntu 11.10 on a VMware player
    Using gcc and running the program from command line
    The 'stty -a' shows eof = ^D</p>
  </blockquote>
  
  <p>thanks for any help..</p>
  
  <pre><code>1 #include &lt;stdio.h&gt;
    2 
    3 int main()
    4 {
    5    int c, nl;
    6    nl = 0;
    7    while ((c != getchar()) != EOF)
    8    {
    9       if (c == '\n')
   10          ++nl;
   11    }
   12    printf("line: %d\n", nl);
   13 
   14    return 0;
   15 }
  </code></pre>