Is it possible to set the standard input/output to a file in C? -
this question has answer here:
can standard input/output set file c programme. know can use fscanf , fprintf read , write file setting std i/o file, can use printf/scanf i/o operations in c programme?
is possible set standard input/output file in c?
yes, can using freopen
.
example code above site:
#include <stdio.h> #include <stdlib.h> int main(void) { puts("stdout printed console"); if (freopen("redir.txt", "w", stdout) == null) { perror("freopen() failed"); return exit_failure; } puts("stdout redirected file"); // written redir.txt fclose(stdout); }