C language Freopen () function: Open the file function and get the file handle
Header file:
To define a function:
FILE * Freopen (const char * path, const char * mode, FILE * stream);
Function Description:
The parameter path string contains the file path and file name that you want to open.
Parameter mode please refer to the fopen () description ...
The parameter stream is an open file pointer. Freopen () closes the file stream that was opened by the original stream, and then opens the file for the parameter path.
Return value: After the file is successfully opened, the file pointer to the stream is returned. Returns null if the file fails to open, and the error code is in errno.
Example
#include <stdio.h>
Main ()
{
FILE * FP;
fp = fopen ("/etc/passwd", "R");
fp = freopen ("/etc/group", "R", FP);
Fclose (FP);
C language Fclose () function: Close Open File
header file:
To define a function:
int fclose (FILE * stream);
Function Description: fclose () is used to close a previously fopen () Open file. This action will cause the data in the buffer to be written to the file and release the file resources provided by the system.
Return value: Returns 0 if the file is successful, returns EOF when an error occurs, and saves the error code to errno.
Error code: EBADF represents a file that is not open for parameter stream.