Defined in header
1) First, attempts to close the file associated with
stream, ignoring any errors. Then, if
filenameis not null, attempts to open the file specified by
modeas if by fopen, and associates that file with the file stream pointed to by
filenameis a null pointer, then the function attempts to reopen the file that is already associated with
stream(it is implementation defined which mode changes are allowed in this case).
2) Same as (1), except that
modeis treated as in fopen_s and that the pointer to the file stream is written to
newstreamptrand the following errors are detected at runtime and call the currently installed constraint handler function:
newstreamptris a null pointer
streamis a null pointer
modeis a null pointer
- As with all bounds-checked functions,
freopen_sis only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including
|filename||-||file name to associate the file stream to|
|mode||-|| null-terminated character string determining new file access mode
|stream||-||the file stream to modify|
|newstreamptr||-||pointer to a pointer where the function stores the result (an out-parameter)|
1) A copy of the value of
streamon success, null pointer on failure.
2) zero on success (and a copy of the value of
streamis written to
*newstreamptr, non-zero on error (and null pointer is written to
newstreamptris itself a null pointer).
freopen is the only way to change the narrow/wide orientation of a stream once it has been established by an I/O operation or by fwide.
The following code redirects
stdout to a file.
stdout is printed to console
- C11 standard (ISO/IEC 9899:2011):
- 220.127.116.11 The freopen function (p: 307)
- K.18.104.22.168 The freopen_s function (p: 590)