I output to stdout. How can I redirect this to a new file using code? While we run the program, we can redirect as ./sample > test.txt . How to do this when executing the sample program itself? (C programming)
./sample > test.txt
You probably want to use freopen .
Example from the link:
#include <stdio.h> ... FILE *fp; ... fp = freopen ("/tmp/logfile", "a+", stdout);
Use freopen() .
freopen()
Use the dup2() system call and redirect the output to a file.
dup2()
Source: https://habr.com/ru/post/1307072/More articles:Python preliminary testing for coverage failure exceptions - pythonMultiplication of a complex with a constant in C ++ - c ++YUI and / or jQuery for a new project? - javascriptDecimal minutes - decimalStrange behavior with large types of objects - performanceHow to determine if a custom C ++ type is registered in tolua - c ++Android and kernel modules - androidMethods for implementing and using node schedules in C ++? - c ++Visual Studio 2010 (backward compatibility support) - .netGmail HTML5 feature to "drop" attachments - htmlAll Articles