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

fread

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


Include

#include <stdio.h>

Signature & Overview

size_t fread(void *restrict buf, size_t size, size_t count, FILE *restrict stream);

Reads up to count objects of size bytes from stream; returns the number of full objects read.

Notes & Pitfalls

Example

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

int main(void) {
    FILE *f = tmpfile();
    fwrite("ABCD", 1, 4, f);
    rewind(f);
    char out[4];
    assert(fread(out, 1, 4, f) == 4 && out[0] == 'A');
    fclose(f);
}

Linked from

Related notes