Tuesday, October 26, 2010

stdout to a file in C

it is very Simple , I tried On AIX

#include
#include
main()
{
FILE *fd1;
fd1=freopen("/tmp/test.log","w",stdout);
if( fd1 == NULL )
{
printf("Error in openng a file");
return -1;
}
printf("This is test message should go in /tmp/test.log file\n");
fclose(fd1);
return 0;

}


What ever you print to stdout will go into a file. Pin It
Related Posts Plugin for WordPress, Blogger...