Close an open file stream.
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>.
| Name | Description | Optional |
|---|---|---|
stream |
Pointer to the FILE object to close. | No |
fclose(fp);