Playing with freopen to redirect stdout.
This commit is contained in:
parent
b1260e7f5c
commit
1789da0d74
22
ex24_iofunctions05.c
Normal file
22
ex24_iofunctions05.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include "dbg.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp;
|
||||
char *filename;
|
||||
check(argc == 2, "You must provide a filename for redirecting stdout.");
|
||||
|
||||
filename = argv[1];
|
||||
fp = freopen(filename, "w", stdout);
|
||||
check(fp != NULL, "Failed to reopen stdout as \"%s\"", filename);
|
||||
|
||||
printf("This should be written to the file you specified!\n");
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user