C I/O

Streams, formatted I/O, byte and wide character operations, file positioning, buffering, and file-management routes in the C library.

C I/O is centered around FILE, standard streams, formatted input/output, byte and wide character operations, buffering, and file-position state. This page is the curated entry point for choosing the right I/O model before dropping into individual functions.

This hub stays focused on the C I/O library. It points to canonical `stdio.h` and `wchar.h` routes, and links outward to adjacent C and C++ areas where the problem is no longer primarily about the C stream model itself.

# Start Here

Streams and file handles

Start here when you need the core model: what a `FILE` is, how standard streams behave, and how streams are opened, reopened, and closed.

Formatted I/O

Use the formatted family when the task is scanning or printing structured text with format strings rather than raw byte transfer.

Byte vs wide character I/O

Use these routes when you are reading or writing individual characters or lines, and need to choose between byte-oriented and wide-oriented stream behavior.

Positioning and buffering

Start here when the problem is seek/tell state, `fpos_t`, rewinding, flushing, buffering, or stream status flags rather than the data representation itself.

# Quick Map

If you need to...Start withWhy
Open, reopen, or close a streamfopen, freopen, fcloseThese functions define the lifetime and access mode of the underlying `FILE` stream.
Read or write formatted text with conversion specifiersfprintf, fscanf, fwprintf, fwscanfThe formatted families sit on top of the stream model and are the right entry point when a format string drives the I/O contract.
Transfer raw objects or byte blocksfread, fwriteThis is the direct route for binary or object-sized transfers where per-character formatting is not wanted.
Read or write one character or one line at a timefgetc/getc, fgets, fputc/putc, fputsThe byte-oriented primitives are the simplest stream surface when the job is textual but not format-string driven.
Use wide-character stream I/Ofgetwc/getwc, fputwc/putwc, fwideWide I/O has orientation rules and runtime behavior that differ from byte-oriented stream use.
Seek, rewind, or store a stream positionfseek, ftell, fgetpos, fsetpos, rewindThese functions deal with the file-position indicator and saved positioning state rather than data format.
Control buffering, flush output, or inspect stream statesetbuf, setvbuf, fflush, feof, ferrorThis route covers performance tuning and stream-status diagnostics.
Create temporary files or manipulate filesystem names through stdiotmpfile, tmpnam, remove, renameThese are the C library file-management entry points adjacent to, but not identical with, open/read/write operations.

# I/O Families

Core stream model

`FILE`, the predefined standard streams, and the lifecycle functions that attach streams to files or devices.

Formatted text I/O

The `printf`/`scanf` families for byte and wide streams, including `va_list`-driven variants.

Block and record transfer

Direct byte/object movement to and from streams for binary files and serialized data.

Byte-oriented character I/O

Single-byte character reads/writes, line-oriented helpers, and pushback for byte streams.

Wide-character I/O

Wide stream reading/writing together with orientation control and pushback semantics.

Positioning and state

Position indicators, `fpos_t`, rewinding, status flags, error clearing, and buffering control.

# Stream Model And State

ConcernPrimary destinationsUse it for
Stream identity and predefined handlesFILE, stdin/stdout/stderrUnderstanding what a stream is and which built-in handles exist before any explicit `fopen` call.
Position trackingfseek, ftell, fgetpos, fsetpos, fpos_tMoving within a file, saving/restoring location, and dealing with implementation-defined position state.
Buffering and flushingsetbuf, setvbuf, fflushControlling buffering policy and forcing buffered output to be written.
Error and EOF statusclearerr, feof, ferror, perrorInspecting stream state after failed operations and reporting human-readable diagnostics.
Byte vs wide orientationfwide, byte I/O, wide I/OChoosing or querying whether a stream is operating in narrow-byte mode or wide-character mode.
TaskGo here
Create a temporary file safely through the standard I/O library.tmpfile
Generate a temporary name only.tmpnam
Delete or rename a filesystem entry through the stdio surface.remove, rename
Leave C stdio and navigate the C++ stream model instead.C++ I/O