Next: Input and Output Up: C File Handling Previous: Standard file pointers

Closing a file using fclose

The fclose command can be used to disconnect a file pointer from a file. This is usually done so that the pointer can be used to access a different file. Systems have a limit on the number of files which can be open simultaneously, so it is a good idea to close a file when you have finished using it.

This would be done using a statement like


  fclose(output_file);

If files are still open when a program exits, the system will close them for you. However it is usually better to close the files properly.


craa27@strath.ac.uk
Tue Jan 17 11:40:37 GMT 1995