title: Rerouting stdin and stdout from C
body: <p>I want to reopen the <code>stdin</code> and <code>stdout</code> (and perhaps <code>stderr</code> while I'm at it) filehandles, so that future calls to <code>printf()</code> or <code>putchar()</code> or <code>puts()</code> will go to a file, and future calls to <code>getc()</code> and such will come from a file.</p>
  
  <p>1) I don't want to permanently lose standard input/output/error. I may want to reuse them later in the program.</p>
  
  <p>2) I don't want to open new filehandles because these filehandles would have to be either passed around a lot or global (shudder).</p>
  
  <p>3) I don't want to use any <code>open()</code> or <code>fork()</code> or other system-dependent functions if I can't help it.</p>
  
  <p>So basically, does it work to do this:</p>
  
  <pre><code>stdin = fopen("newin", "r");
  </code></pre>
  
  <p>And, if it does, how can I get the original value of <code>stdin</code> back? Do I have to store it in a <code>FILE *</code> and just get it back later?</p>