title: Different behaviour of Ctrl-D (Unix) and Ctrl-Z (Windows)
body: <p>As per title I am trying to understand the exact behavior of <kbd>Ctrl</kbd>+<kbd>D</kbd> / <kbd>Ctrl</kbd>+<kbd>Z</kbd> in a while loop with a gets (which I am required to use). The code I am testing is the following:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
  
      char str[80];
  
      while(printf("Insert string: ") &amp;&amp; gets(str) != NULL) {
  
          puts(str);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>If my input is simply a <kbd>Ctrl</kbd>+<kbd>D</kbd> (or <kbd>Ctrl</kbd>+<kbd>Z</kbd> on Windows) <code>gets</code> returns NULL and the program exits correctly. The unclear situation is when I insert something like <code>house^D^D</code> (Unix) or <code>house^Z^Z\n</code> (Windows). </p>
  
  <ol>
  <li>In the first case my interpretation is a <code>getchar</code> (or something similar inside the <code>gets</code> function) waits for read() to get the input, the first <kbd>Ctrl</kbd>+<kbd>D</kbd> flushes the buffer which is not empty (hence not EOF) then the second time read() is called EOF is triggered.</li>
  <li>In the second case though, I noticed that the first <kbd>Ctrl</kbd>+<kbd>Z</kbd> is inserted into the buffer while everything that follows is simply ignored. Hence my understanding is the first read() call inserted <code>house^Z</code> and discarded everything else returning 5 (number of characters read). (I say 5 because otherwise I think a simple <kbd>Ctrl</kbd>+<kbd>Z</kbd> should return 1 without triggering EOF). Then the program waits for more input from the user, hence a second read() call.</li>
  </ol>
  
  <p>I'd like to know what I get right and wrong of the way it works and which part of it is simply implementation dependent, if any.</p>
  
  <hr>
  
  <p>Furthermore I noticed that in both Unix and Windows even after EOF is triggered it seem to reset to false in the following <code>gets()</code> call and I don't understand why this happens and in which line of the code.</p>
  
  <p>I would really appreciate any kind of help.</p>
  
  <hr>
  
  <p>(12/20/2016) I heavily edited my question in order to avoid confusion</p>