Closing a File In C

During a write to a file, the data written is not put on the disk immediately. It is stored on a buffer. When the buffer is full, all its contents are actually written to the disk. The process of emptying the buffer by writing its contents to disk is called flushing the buffer.

Closing the file flushes the buffer and releases the space taken by the FILE structure which is returned by fopen(). Operating systems normally impose a limit on the number of files that can be opened by a process at a time .Hence closing a file means that another can be opened in its place .Hence if a particular FILE Pointers is not required after a certain point in a program,pass it to fclose() and close the file.The prototype of fclose() function is

Int fclose(FILE *fp);

Where fp is the file pointer returned by the call to fopen(). A return value 0 indicates a successful close operation where as any other values signify the error.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext