title: Redirect stderr to both file and stdout in C
body: <p>Is there a way to write the error messages to a log file and also print them on the terminal screen?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>dup2(fileno(pFile), STDERR_FILENO); /* redirect stderr to file */
  </code></pre>
  
  <p>which redirects <strong>stderr</strong> to the file. However, that writes the error messages to the file but does not show them on screen.</p>
  
  <p>Can this be done without reading and copying the contents of stderr to the file?</p>
  
  <p><strong>Note:</strong> I would like to not invoke the shell (system, popen). I did look the implementation of the <code>tee</code> command of <code>coreutils</code>. It copies the standard stream to files.</p>