문제

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.

도움이 되었습니까?

해결책

You can use freopen()

// code copied from the link
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top