C Examples
Aligned plain-text CLI table renderer in ANSI C
Prints a header, divider, and rows in aligned columns, sizing each column to its widest header or cell value.
Base64 encode and validating decode in compact C
Encodes bytes to padded base64 with a 24-bit loop, then decodes and rejects invalid characters or misplaced padding.
Field-level form validation with error pointers in C
Checks required name, email format, and age limits, returning per-field error messages and the number of failed fields.
Percent-encode and decode URL query component strings in C
Percent-encodes a URL query component and decodes plus signs or percent triplets back to bytes with bounded buffers.
Decode JSON string escapes with error offsets in C
Decodes a quoted JSON string with common escapes, returning the consumed length or reporting the byte offset of the first error.
Fixed-size pthread pool processing job slices in C
Splits a job array across at most eight pthreads and records each job callback's return value as a per-job error code.
Socket HTTP GET JSON code extractor with timeouts in C
Sends a minimal IPv4 HTTP GET with a receive timeout and extracts the integer code field from the JSON response body.
Typed env config with defaults and range checks in C
Reads environment variables with type-safe defaults, rejecting malformed integers or values outside the supplied inclusive range.
Array-backed LRU cache with bounded capacity in C
Implements a fixed-capacity least-recently-used cache over an array, moving hits to the front and evicting the oldest entry.
Monotonic token bucket rate limiter in portable C
Initializes and refills a token bucket from a monotonic clock, allowing bursts up to capacity while enforcing an average rate.
Stable multi-key record sorting with nulls in C
Sorts records by name ascending with null names last, then by age, using the original index to keep equal keys stable.
Split an array into fixed-size batches with a callback in C
Calls a visitor once per contiguous batch of an array, advancing by element width and returning the batch count.
Stream a text file line by line with getline in C
Opens a text file and invokes a callback for every line, stripping CR and LF and reporting the accumulated result.
Deep clone and recursive merge for a binary tree in C
Recursively duplicates a string-keyed binary tree and merges another tree into it, replacing values on key matches.
Capped exponential backoff with jittered retry loop
Runs a callback until it succeeds, sleeping with capped exponential backoff and random jitter between attempts.