From 1789da0d748475194859ece61699dfb5bc8d90d3 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 12 Nov 2011 11:05:16 -0500 Subject: [PATCH] Playing with freopen to redirect stdout. --- ex24_iofunctions05.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ex24_iofunctions05.c diff --git a/ex24_iofunctions05.c b/ex24_iofunctions05.c new file mode 100644 index 0000000..d733709 --- /dev/null +++ b/ex24_iofunctions05.c @@ -0,0 +1,22 @@ +#include +#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; +}