FREOPEN - re-open a previously opened file.

(ANSI Standard)

Usage:

#include <stdio.h>
ret = freopen( name, options, f );

Where:

const char *name;
is a string containing the name of the file to be opened.
const char *options;
is a string indicating whether the file should be opened for reading or writing. This string has the same form as the options string for "fopen".
FILE *f;
is an existing file pointer pointing to the file that is to be reopened.
FILE *ret;
is a file pointer for the newly (re)opened file. A null pointer is returned if the function fails to reopen the file.

Description:

"freopen" is like "fopen", except that the caller supplies a pointer for a previously opened file. The old file is closed and the new file replaces it. "freopen" returns a pointer to the opened file.

This is the only way to reassign "stdin", "stdout", and "stderr", which are opened prior to the start of the main program.

Copyright © 1996, Thinkage Ltd.