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

fopen

Prev: fputs | Up: stdio.h | Next: fclose
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — fopen
Tags: #public #prog #c #stdlib #stdio #tier/core


Include

#include <stdio.h>

Signature & Overview

FILE *fopen(const char *restrict path, const char *restrict mode);

Opens a file stream ("r", "w", "a", "rb", "wb", "wx"); returns NULL on failure and sets errno.

Notes & Pitfalls

Example

#include <assert.h>
#include <stdio.h>

int main(void) {
    FILE *f = fopen("nonexistent_demo_xyz", "rb");
    assert(f == NULL);
}

Linked from

Related notes