I want to redirect stdout to a file ... and after I print something I want to go back to print to the usual screen output. I can't get back to printing on the screenCode:int main(int argc, char *argv[])
{
int f = open("test.txt", O_CREAT|O_RDWR, 0666);
int out=dup(1);
if(f==-1)
perror("open()");
dup2(f, 1);
printf("Hello world\n");
printf("%d\n",close(f));
close(1);
printf("test\n");
return 0;
}
Please help!