How do I 'restore' my output (stdout) back to the terminal after redirecting it to a file. I want to be able to output to a file for a specific section of code, then close that file and put output back to the screen/terminal.
fprintf(stdout, "This will go to the terminal.\n");
stdout = fopen("/tmp/somefile.txt", "w");
fprintf(stdout, "This will go to the file /tmp/somefile.txt.\n");
...
fclose(stdout);
fprintf(stdout, "I WANT this to go to the terminal.\n");
Using this code, I get nothing after the close (obviously closing is wrong). How do I restore the output?