Programming Reference/Librarys
Question & Answer
Q&A is closed
#include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ FILE *freopen( const char *fname, const char *mode, FILE *stream );
closes file associated with stream, then opens file filename with specified mode and associates it with stream. Returns stream or NULL on error.
/* * freopen example code * http://code-reference.com/c/stdio.h/freopen */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ int main ( void ) { freopen ("test.txt","w",stdout); printf ("This content is written to a file"); fclose (stdout); return 0; }
user@host:~$ ./freopen
user@host:~$ cat test.txt
This content is written to a file