title: fputs(), fgets(), ferror() questions and C++ equivalents
body: <p>So I was reading a book on writing a shell in C and I want to try to write it in C++.  I came across the following code:</p>
  
  <pre><code>for( ; ; ) 
  {
      if (fputs(PROMPT, stdout) == EOF)
          continue;
  
      if (fgets(inbuf, MAX, stdin) == NULL)
          continue;
  
      //and so on....
  }
  </code></pre>
  
  <ol>
  <li><p>I don't understand the usage of <code>fputs()</code> here.</p>
  
  <p>(a) if stdout is a terminal, does EOF have any meaning?  What kind of errors can you get writing to a terminal except maybe the stream is already closed?</p>
  
  <p>(b) if stdout was previously redirected and is really a pipe or file then several different errors seem possible.  Where are they listed?  See (c) below.</p>
  
  <p>(c) following (b) above, ferror() doesn't seem that helpful.  Does its return values map to those of errno and thus the same as using something like perror()?  Where are the constants kept in order to do something like</p>
  
  <pre><code>  if (ferror() == SYSTEM_ERROR_13)
  </code></pre>
  
  <p>(d) in the code above, if fputs() did return an error why would a "continue" work?  Wouldn't the error need to be cleared first with something like clearerr() or it would just repeatedly fail?</p></li>
  <li><p>Is the equivalent code in C++:</p>
  
  <pre><code>for( ; ; ) 
  {
      if (! cout &lt;&lt; PROMPT)
      {
          cout.clear();
          continue;
      }
  
      if (! getline(cin, inbuf))
      {
          cin.clear();
          continue;
      }
  
      //and so on....
  }
  </code></pre></li>
  </ol>