Standard streams stdin, stdout, stderr, and freopen() function for redirecting standard streams in C

When a program starts running there are three standard streams stdin (standard input), stdout (standard output), and stderr (standard error) which open automatically. Out of these three streams stdin is used to read from the console, and stdout and stderr are used to write to the console. These standard streams can be used as a file pointer in any function however, they should not be assigned a value.

freopen() function: freopen() fucntion is used to redirect the standard streams and associates an existing stream with a new file.


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

here, filename is a pointer to the filename.

and file is opened using the value of mode.

Leave a Reply