On this page
  1. fclose
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

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

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