Most of the times, its a requirement that the standard pipes (stdin, stdout, stedrr) to be redirected to a different file stream by the program.. freopen() does the job.
The freopen() function opens the file whose name is the string pointed to by path and associates the stream pointed to by stream with it.
The original stream (if it exists) is closed. The mode argument is used just as in the fopen() function. The primary use of the freopen()
function is to change the file associated with a standard text stream (stderr, stdin, or stdout).
for ex:
freopen(myfile, "w", stdout);