gtpc2m25 | C/C++ Language Support User's Guide |
This function closes a file stream.
Format
#include <stdio.h> int fclose(FILE *stream);
This function flushes a stream and then closes the file associated with that stream. The function then releases any buffers associated with the stream. To flush means that unwritten buffered data is written to the file and buffered data that is not read is discarded.
A pointer to a closed file cannot be used as an input value to the freopen function.
Normal Return
If successful, the fclose function returns 0.
Error Return
If a failure occurs when flushing buffers or in outputting data, EOF is returned. An attempt is still made to close the file.
The fclose function sets errno to one of the following:
Programming Considerations
None.
Examples
The following example opens the file myfile.dat for reading as a stream and then closes the file.
#include <stdio.h> int main(void) { FILE *stream; stream = fopen("myfile.dat", "r");
·
·
·
if (fclose(stream)) /* Close the stream. */ printf("fclose error\n"); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.