title: While loop never exits for EOF
body: <p>I'm writing my own shell in C and I need to detect EOF (for when I run <code>./myshell &lt; commands.txt</code>)</p>
  
  <p>commands.txt contains:</p>
  
  <pre><code>ls
  pwd
  </code></pre>
  
  <p>These both run fine separately from within the program. But when I run it with the text file, I get an infinite loop.</p>
  
  <p>In my <code>while(1)</code> loop for the shell, the first thing I do is this:</p>
  
  <pre><code>if (feof(stdin)) { my_exit(); }
  </code></pre>
  
  <p><code>my_exit</code> is simply:</p>
  
  <pre><code>void my_exit() {
      printf("End of file! Bye\n");
      exit(0);
  }
  </code></pre>
  
  <p>Doesn't <code>exit(0)</code> end the program (and the loop)? Why am I getting </p>
  
  <blockquote>
    <p>End of File! ByeEnd of File! ByeEnd of File! ByeEnd of File! ByeEnd of File! ByeEnd of File! Bye.... etc</p>
  </blockquote>
  
  <p>I have also tried doing the <code>fgets == NULL</code> way. Same loop</p>