:
This message was edited by stober at 2006-5-19 7:46:32
: : I want to redirect output of printf and perror to a file in a C program. Please anyone help me how to do it. I also tried this by the help of system() funtion but it did not work.
: : For example i want to print the messages below to a file without using fprintf. Even if the file is opened.
: :
: : fp=fopen("abc.txt","w");
: :
: : printf("\nHai How are You ?\n");
: : perror("\n I AM HERE\n");
: :
: :
: : I want that both the above statements should write into the file abc.txt not at stdout or stderr ie console.
: : Please help. Thanks
: :
: :
: :
:
:
: you are using the wrong function.
: fprintf(fp,"\nHai How are You ?\n");
:
: perror goes to stderr, not to a file. So you have to call freopen() as previously suggested.
: stream = freopen( "abc.tct", "w", stderr );
:
: see the example program here:
:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_freopen.2c_._wfreopen.asp
:
:
:
:
He mentioned that he didn't want to use fprintf. So I figured he knows that function and has some argument not to use it.
Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl