Originally Posted by
vsriharsha
Is it not feasible for you to declare a global file pointer for that file and open it first in the main function (before you start redirecting out put to it) and then use that same filepointer everywhere.
Except that you are using global variables when you can easily just pass it around and have things be a lot safer.
Example:
Code:
#include <stdio.h>
void func(FILE *);
int main(void)
{
FILE *out = stdout;
if ( out == NULL )
return 1;
fprintf(out, "%s", "Hello world\n");
func(out);
return 0;
}
void func (FILE *out)
{
fprintf(out, "Hello my name is bob\n");
}
Now just replace
Code:
FILE *out = stdout;
with an fopen() call.