Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C fclose

    C fclose() function is a C library function that releases the memory stream opened by the fopen() function. This tutorial guides you on how to use the fclose() function in the C program. The basic format of the fclose is:

    Syntax:

    int fclose( FILE * stream );

    Return Value

    The C close() function returns EOF in case of failure and returns 0 on success.

    Example:

    #include<stdio.h>
    
    int main()
    {
        FILE *fp;
        fp = fopen("fileName.txt","w");
        fprintf(fp, "%s", "Sample Texts");
        fclose(fp);
        return 0; 
    }

    Explanation:

    • The above example will create a file called fileName.txt.
    • The w means that the file is being opened for writing, and if the file does not exist, then the new file will be created.
    • The fprintf() function writes Sample Texts text to the file.
    • The fclose() function closes the file and releases the memory stream.


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.