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)
3 Answers
You probably want to use freopen.
Example from reference:
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);