How to close the file in C explain with example
CLOSING A FILE:
A file must be closed as soon as all operations on it have been completed. This ensures that all outstanding information associated with the file is flushed out from the buffers and all links to the file are broken.
This would close the file associated with the FILE pointer file_pointer.
The following segment of a program:
…………
…………
FILE *p1, *p2;
p1 = fopen(“INPUT”, “w”);
p2 = fopen(“OUTPUT”, “r”);
…………
………….
fclose(p1);
fclose(p2);
………..
This program opens two files and closes them after all operations on them are completed.