Syntax
#include <stdio.h> int fclose(FILE *stream);Description
fclose closes a stream pointed to by stream. This function flushes all buffers associated with the stream before closing it. When it closes the stream, the function releases any buffers that the system reserved. When a binary stream is closed, the last record in the file is padded with null characters (\0) to the end of the record.
fclose returns 0 if it successfully closes the stream, or EOF if any errors were detected.
Note: Once you close a stream with fclose, you must open it again before you can use it.
This example opens a file fclose.dat for reading as a stream; then it closes this file.
#include <stdio.h> int main(void) { FILE *stream; stream = fopen("fclose.dat", "r"); if (0 != fclose(stream)) /* Close the stream */ perror("fclose error"); else printf("File closed successfully.\n"); return 0; /**************************************************************************** The output should be: File closed successfully. ****************************************************************************/ }Related Information