Pelles C forum
C language => Tips & tricks => Topic started by: JohnF on August 01, 2007, 07:58:40 AM
-
When debugging a large project it is sometimes convenient to print to a file. Instead of using fprintf and carrying around a file handle you can redirect stdout to a file and use printf.
As an example, at the top of WinMain
fclose(stdout);
*stdout = *fopen("c:\\debug.log", "w");
Then use printf throughout the project.
stdout is closed on exit but one could close it manually before one exits.
fclose(stdout);
I don't know if this is considered bad practice but it works.
John
-
you can also use
freopen("file.txt","wt",stdout);