On this page
fclose
Prev: fopen | Up: stdio.h | Next: fread
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — fclose
Tags: #public #prog #c #stdlib #stdio #tier/core
Include
#include <stdio.h>
Signature & Overview
int fclose(FILE *stream);
Flushes buffered writes and closes stream; returns 0 on success or EOF on error.
Notes & Pitfalls
- Always check
fclose()return value on write streams: Buffered writes may only flush to disk duringfclose(), so disk-full errors can surface here. Never callfclose()twice on the same handle.
Example
#include <assert.h>
#include <stdio.h>
int main(void) {
FILE *f = tmpfile();
assert(f != NULL);
fputs("ok", f);
assert(fclose(f) == 0);
}
Linked from
Related notes
- tuts/c/stdlib/stdio/fopen Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fread Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/ferror shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fprintf shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fputs shared tags: #c, #prog, #stdio, #stdlib, #tier