← All languages
C function of the day
Random

fclose

Close an open file stream.

Description

The fclose() function flushes the stream pointed to by stream and closes the underlying file descriptor. Any buffered output data is written to the file, and any buffered input data is discarded.

If the stream was successfully closed, fclose() returns 0. On failure, it returns EOF and sets errno to indicate the error. After calling fclose(), the stream pointer should not be used.

It is important to close files when they are no longer needed to release system resources and ensure data integrity. It is declared in <stdio.h>.

Arguments

NameDescriptionOptional
stream Pointer to the FILE object to close. No

Example

fclose(fp);