freopen
- Updated2023-02-21
- 2 minute(s) read
FILE *freopen (const char fileName[], const char mode[], FILE *oldStream);
Purpose
Does the following:
- Attempts to close the file that is associated with oldStream—failure to close the file successfully is ignored
- Opens a file and associates it with the I/O stream that is pointed to by oldStream
- Clears error and end-of-file indicators for the I/O stream
![]() |
Note This function is useful for redirecting the standard streams (stdin, stdout, stderr) to a file. |
If the open operation fails, fopen returns NULL and sets errno to a nonzero value.
Parameters
Input | ||||||||||||||||||||||||||||
Name | Type | Description | ||||||||||||||||||||||||||
fileName | const char [] | Specifies the name of the new file that is opened. The I/O stream associated with oldStream is associated with this file. | ||||||||||||||||||||||||||
mode | const char [] |
Specifies the mode of reading and writing for the opened file.
The possible modes are listed in the following chart:
|
||||||||||||||||||||||||||
oldStream | FILE * | Contains a pointer to the I/O stream that is redirected. The file formerly associated with this stream is closed if possible. |
Return Value
Name | Type | Description |
newStream | FILE * | Contains a pointer to the new I/O stream associated with the opened file if successful. If the open operation fails, fopen returns NULL and sets errno to a nonzero value. |
Additional Information
Library: ANSI C Library
Include file: ansi_c.h
LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later