Skip to content
UPEEC

Files and the C Standard Library

File I/O, error handling and the standard headers every C programmer uses.

Easy
Comments 0

This is an overview — pick a sub-topic below.

Sub-topics (19)

File Handling in C

Open a file as a `FILE *` stream, read or write, then close it.

Beginner♥ 0🔖 0💬 0

fread and fwrite

Read and write blocks of bytes — ideal for binary data.

Easy♥ 0🔖 0💬 0

fprintf and fscanf

Formatted output to and input from files — `printf`/`scanf` for streams.

Beginner♥ 0🔖 0💬 0

fgets and fputs

Read a line safely into a buffer; write a string.

Beginner♥ 0🔖 0💬 0

fseek and ftell

Move the file position and report where it is.

Easy♥ 0🔖 0💬 0

Binary Files

Store data as raw bytes instead of text — smaller and faster, but needs a defined format.

Easy♥ 0🔖 0💬 0

Error Handling in C

C has no exceptions: functions return error codes, NULL or set `errno`.

Easy♥ 0🔖 0💬 0

errno

A global (thread-local) error number set by library functions on failure.

Easy♥ 0🔖 0💬 0

The C Standard Library

The headers that come with every C compiler: I/O, strings, maths, memory, time and more.

Beginner♥ 0🔖 0💬 0

assert.h

`assert(condition)` aborts with a message if a programmer assumption is false.

Easy♥ 0🔖 0💬 0

math.h

Floating-point maths: `sqrt`, `pow`, `sin`, `cos`, `atan2`, `fabs`, `floor`, `round`, `log`, `exp`.

Beginner♥ 0🔖 0💬 0

stdlib.h

General utilities: memory (`malloc`, `free`), conversions (`strtol`, `strtod`), `qsort`, `bsearch`, `rand`, `exit`, `abs`.

Beginner♥ 0🔖 0💬 0

stdint.h

Fixed-width integer types: `int8_t`, `uint16_t`, `int32_t`, `uint64_t`, plus `uintptr_t` and limits.

Beginner♥ 0🔖 0💬 0

stdbool.h

Defines `bool`, `true` and `false` (built-in keywords since C23).

Beginner♥ 0🔖 0💬 0

stdatomic.h

C11 atomic types and operations for lock-free shared data between threads or interrupts.

Advanced♥ 0🔖 0💬 0

signal.h

Handle asynchronous signals like `SIGINT` (Ctrl+C).

Intermediate♥ 0🔖 0💬 0

time.h

Calendar time, clocks and formatting: `time`, `clock`, `difftime`, `strftime`, `localtime`.

Easy♥ 0🔖 0💬 0

locale.h

Localisation settings that affect number formatting and character classification.

Intermediate♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.