Reputation: 347
I am outputting to stdout. How can I redirect that to a new file through code? While we run the program we can redirect like ./sample > test.txt
. How can I do this when executing the sample program itself ? (C programming)
Upvotes: 5
Views: 5815
Reputation: 532695
You probably want to use freopen.
Example from reference:
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
Upvotes: 8