C Language: freopen function(Reopen File)

In the C Programming Language, the freopen function first closes the file associated with stream. Then the freopen function opens filename and associates it with stream. In essence, it associates a different file to a stream that is already open.


The syntax for the fopen function in the C Language is:

FILE *freopen(const char *filename, const char *mode, FILE *stream);

Parameters or Arguments


The filename to associate with the file being reopened.


The mode in which to open the file.


The stream to associate with filename.


The freopen function returns a file pointer for the opened file. If the file can not be opened, the freopen function returns a null pointer.

Required Header

In the C Language, the required header for the freopen function is:

#include <stdio.h>

Applies To

In the C Language, the freopen function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions