C Standard Libraries C++

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.

Input File

fclose() Input File

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;
}

Output

fclose() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.