You can use freopen()
// code copied from the link
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
...
Pergunta
I want to write a function which would redirect the standard output to a file where the name of the file is "name".log where "name" is the argument to the function
void redirect(char *name) {
I don't know where to begin.
Solução
You can use freopen()
// code copied from the link
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
...