InterviewSolution
| 1. |
How To Restore A Redirected Standard Stream? |
|
Answer» The preceding example showed how you can redirect a standard stream from within your PROGRAM. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C LIBRARY functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state. The dup() function duplicates a file handle. You can use the dup() function to save the file handle CORRESPONDING to the stdout standard stream. The fdopen() function OPENS a stream that has been duplicated with the dup() function. The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state. The dup() function duplicates a file handle. You can use the dup() function to save the file handle corresponding to the stdout standard stream. The fdopen() function opens a stream that has been duplicated with the dup() function. |
|