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.
# 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.
FILE · stdin/stdout/stderr · fopen · fclose
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 with | Why |
|---|---|---|
| Open, reopen, or close a stream | fopen, freopen, fclose | These functions define the lifetime and access mode of the underlying `FILE` stream. |
| Read or write formatted text with conversion specifiers | fprintf, fscanf, fwprintf, fwscanf | The 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 blocks | fread, fwrite | This 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 time | fgetc/getc, fgets, fputc/putc, fputs | The byte-oriented primitives are the simplest stream surface when the job is textual but not format-string driven. |
| Use wide-character stream I/O | fgetwc/getwc, fputwc/putwc, fwide | Wide I/O has orientation rules and runtime behavior that differ from byte-oriented stream use. |
| Seek, rewind, or store a stream position | fseek, ftell, fgetpos, fsetpos, rewind | These functions deal with the file-position indicator and saved positioning state rather than data format. |
| Control buffering, flush output, or inspect stream state | setbuf, setvbuf, fflush, feof, ferror | This route covers performance tuning and stream-status diagnostics. |
| Create temporary files or manipulate filesystem names through stdio | tmpfile, tmpnam, remove, rename | These 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.
FILE · standard streams · fopen · freopen
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
| Concern | Primary destinations | Use it for |
|---|---|---|
| Stream identity and predefined handles | FILE, stdin/stdout/stderr | Understanding what a stream is and which built-in handles exist before any explicit `fopen` call. |
| Position tracking | fseek, ftell, fgetpos, fsetpos, fpos_t | Moving within a file, saving/restoring location, and dealing with implementation-defined position state. |
| Buffering and flushing | setbuf, setvbuf, fflush | Controlling buffering policy and forcing buffered output to be written. |
| Error and EOF status | clearerr, feof, ferror, perror | Inspecting stream state after failed operations and reporting human-readable diagnostics. |
| Byte vs wide orientation | fwide, byte I/O, wide I/O | Choosing or querying whether a stream is operating in narrow-byte mode or wide-character mode. |