Declaration:
unsigned long freopen(char file_name[], char mode[], unsigned long stream);
Description
Associates a new file with an opened stream.
freopen substitutes the specified file in place of the open stream. It closes the stream regardless of whether the open succeeds. freopen is useful for changing the file attached to stdin, stdout, or stderr. The mode string used in calls to fopen is one of the following values:
Value Description
---------------------------
r Open for reading only.
w Create for writing.
a
r+ Open an existing file for update (reading and writing).
w+ Create a new file for update.
a+ Open for append; open (or create, if the file does not exist) for update at the end of file.
To specify that the given file is being opened or created in the text mode, append t to the value of the type string (for example, rt or w+t).
Similarly, to specify the binary mode, append brb or w+b). If t or b is not given in the type string, the mode is controlled by the _fmode global variable. If _fmode is set to O_BINARY, then files will be opened in the binary mode. If _fmode is set to O_TEXT, then files will be opened in the text mode.
Note. The O_* constants are defined in file system.h.
When a file is opened for update, both input and output can be done on the resulting stream; however,
•
|
output cannot be directly followed by input without intervening fseekor rewind;
|
•
|
input cannot be directly followed by output without intervening fseek, rewind, or an input that encounters end-of-file.
|
On successful completion freopen returns the argument stream. On error it returns NULL.
|