tags:

views:

85

answers:

2

Hi,

I am having the output in stdout. how to redirect that to a new file through code ? While we run the program we can redirect like ./sample > test.txt. how to make this happen when executing the sample program itself ? (C programming)

Thanks, Vinod.

+3  A: 

Use freopen().

Bastien Léonard
+4  A: 

You probably want to use freopen.

Example from reference:

#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
tvanfosson
Thanks ... I ll try that out