fclose() function is C library function and it's used to releases the memory stream, opened by fopen() function.

The basic format of fclose is:

int fclose( FILE * stream );

Return Value

C fclose returns EOF in case of failure and returns 0 on success.


int main()
    FILE *fp;
    fp = fopen("fileName.txt","w");
    fprintf(fp, "%s", "Sample Texts");
    return 0; 
  • 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.