I want to reopen the stdin
and stdout
(and perhaps stderr
while I'm at it) filehandles, so that future calls to printf()
or putchar()
or puts()
will go to a file, and future calls to getc()
and such will come from a file.
1) I don't want to permanently lose standard input/output/error. I may want to reuse them later in the program.
2) I don't want to open new filehandles because these filehandles would have to be either passed around a lot or global (shudder).
3) I don't want to use any open()
or fork()
or other system-dependent functions if I can't help it.
So basically, does it work to do this:
stdin = fopen("newin", "r");
And, if it does, how can I get the original value of stdin
back? Do I have to store it in a FILE *
and just get it back later?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…