On Thu, Nov 07, 2002 at 03:26:59PM -0500, Scott Williams wrote:
> Hi,
>
> Here's my problem. I have C code that does a bunch of number crunching,
> spitting out intermediate results to the output files along the way.
> However, in some applications, it would be preferable to NOT write any data
> to output files (e.g., when the program is run iteratively in an nonlinear
> optimization routine).
>
> Rather than hunt through my code to find all the instances of fprintf(fpout,
> ...) and insert a conditional statement, it would be much easier (and
> cleaner) if I could simply initialize the file pointer to a stream going
> nowhere.
>
> I've tried setting fpout = NULL but that doesn't work. Any suggestions?
>
> Scott
>
If all your output goes to one stream, pointed by "fpout", and it
is connected to the same file, then all you need to do is modify
code at the point where you connect the stream to the file.
That means replacing:
...
FILE *fpout = fopen("logfile", "w");
...
with something like:
...
FILE *fpout = fopen((condition) ? "logfile" : "/dev/null", "w");
...
to create a CONDITION, a command line flag could be used; so it is
easy to toggle between keeping and discarding intermediate output.
If you are using Dos/Win, then use "nul" in place of "/dev/null".
Regards
--
>> gisan >>
Q: How can you tell when a Burroughs salesman is lying?
A: When his lips move.
|