I have a program where I want to duplicate some of the output to stdout in a text file for caching. It looks something like this:
FILE* cache;
// Open file, check for errors, etc.
fprintf(stdout, "My data\n");
fprintf(cache, "My data\n");
for (int i = 0; i < 10; ++i)
{
fprintf(stdtout, "%d ", i);
fprintf(cache, "%d ", i);
}
Is there some way to get a FILE *
where if I write to it, I get output in both stdout
and my cache file?
(It doesn't work to just redirect it in the shell; the program needs to decide this, not the caller.)