title: Nonsensical output stream during the usage of "getchar()" and "EOF"
body: <p>I have been experimenting with <code>getchar()</code>, <code>putchar()</code> and have been trying to use <code>EOF</code>. Below is the snippet of code I have been experimenting with.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int c;
      c = getchar();
  
      while(c != EOF)
      {
          putchar(c);
          printf("\n");
          printf("%d\n", EOF);
          c = getchar();
      }
  
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Input: -</strong> </p>
    
    <p>a</p>
    
    <p><strong>Expected output: -</strong></p>
    
    <p>a <code>//Due to putchar()</code></p>
    
    <p>-1 <code>//Value of EOF</code> </p>
    
    <p><code>//Now the cursor should come in next line and wait for next character.</code></p>
    
    <p><strong>Output getting in real time: -</strong></p>
    
    <p>a </p>
    
    <p>-1</p>
    
    <p>-1</p>
    
    <p><code>//Cursor waiting for next character.</code></p>
  </blockquote>
  
  <p>I am not able to comprehend the reason why the output is showing <code>-1</code> two times.</p>