Site hosted by Angelfire.com: Build your free website today!



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. All 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 by a statement like


  fclose(output_file);

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