fclose()

Declaration

int fclose(FILE* qpStream);

Description:

This function is used to close stream when you are finished using it. The argument "qpStream" is the stream that gets closed. The function returns 0 if the stream was successfully closed and EOF to indicate an error.

Example

#include <cstdio>

int main()
{
    FILE* qpFile;

    char* cpFileName = "XoaX.txt";

    qpFile = fopen(cpFileName, "r" );
    // Verify that we opened the file.
    if (qpFile) {
        printf("Opened the file %s for reading \n",  cpFileName);
    } else {
        printf("Could not open %s for reading \n",  cpFileName);
        return 1;
    }

    // Now close the file and verify that it closed.
    int iCloseResult = fclose(qpFile);
    if (iCloseResult == 0) {
        printf("Closed the file %s\n",  cpFileName);
    } else {
        printf("Could not close the file %s\n",  cpFileName);
    }

    return 0;
}

Input File:

fclose() Input

Output:

fclose() Output