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)
You probably want to use freopen.
Example from reference:
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With