title: C restore stdout to terminal
body: <p>I am working with a multi-thread program. </p>
  
  <p>First I redirect my stdout to a certain file. No problem there (I used <code>dup2(fd, 1)</code> where <code>fd</code> is the file descriptor for the file). </p>
  
  <p>Afterwards, I need to redirect my stdout to the terminal again.</p>
  
  <p>My first approach:</p>
  
  <pre><code>      /*Declaration*/
        fpost_t  stream_sdout;
        /*code*/
        if ( fgetpos( stdout, &amp;stream_sdout) == -1 )
            perror(Error:);
  </code></pre>
  
  <p>It says illegal seek.<br>
  No idea why this is happening.<br>
  But if I get this to work, then I only need to use <code>fsetpos(stdout, &amp;stream_stdout)</code> and it should work.</p>
  
  <p>My second idea, was to to copy the stdout using <code>dup2(stdout, 4)</code> to the file descriptor table, at position 4. But that ain't working either.</p>
  
  <p>How can I switch the standard output back to its original destination (terminal, pipe, file, whatever)?</p>