title: cat breaks the program, manual stdin input doesn't
body: <p>I have this small program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main() {
      int orig = 1;
      for (int i = 0; (i != 3) &amp;&amp; orig; ++i) {
          orig = orig &amp;&amp; fork();
      }
      if (orig) {
          for (int i = 0; i != 3; ++i) {
              wait(NULL);
          }
      } else {
          int num;
          scanf("%8d", &amp;num);
          printf("%d\n", num*num);
      }
  }
  </code></pre>
  
  <p>Which is  supposed to simply square three numbers that it reads from <code>stdin</code>. And if I type the numbers in myself, it works:</p>
  
  <pre><code>akiiino$ ./out.out
  12345678
  12345678
  12345678
  260846532
  260846532
  260846532
  </code></pre>
  
  <p>but if I use cat for the same purpose, it does not work as expected:</p>
  
  <pre><code>akiiino$ cat in.txt
  12345678
  12345678
  12345678
  
  akiiino$ cat in.txt | ./out.out
  260846532
  0
  0
  </code></pre>
  
  <p>What is the reason behind this weird behavior and is it fixable? I've always assumed <code>cat</code>ing files was no different from typing them into <code>stdin</code>.</p>