Once we open a file, finished reading from the file, we need to close the file. This is done using the function fclose() through the statement:
Once we are done with closing the file, we can no longer read, write or perform any operation on the file unless we reopen it. Note that to close the file, we don’t use the filename but the file pointer
fp. On closing the file, the buffer associated with the file is removed from memory.
While performing a write operation on a file, when we try to close the file using
fclose(), three operations would be performed:
- The character in the buffer would be written to the file on the disk
- At the end of the file a character with ASCII value 26 would be written
- The buffer would be eliminated from memory