C Examples

COct 23, 2026

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.

formattingtablecli
000
COct 23, 2026

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.

decodingvalidationencodingbase64
000
COct 23, 2026

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.

errorsvalidationforms
000
COct 23, 2026

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.

query-stringurlencodinghttp
000
COct 23, 2026

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.

parsingerrorsstringsjson
000
COct 23, 2026

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.

concurrencyworker-poolpthreadserrors
000
COct 23, 2026

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.

socketshttpjsontimeout
000
COct 23, 2026

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.

environmentconfigvalidation
000
COct 23, 2026

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.

evictionarrayslrucache
000
COct 23, 2026

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.

token-bucketposixrate-limitingtime
000
COct 23, 2026

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.

stableqsortsortingrecords
000
COct 23, 2026

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.

arrayscallbackschunks
000
COct 23, 2026

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.

linesioposixfiles
000
COct 23, 2026

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.

mergerecursionclonetrees
000
COct 23, 2026

Capped exponential backoff with jittered retry loop

Runs a callback until it succeeds, sleeping with capped exponential backoff and random jitter between attempts.

posixbackoffretryjitter
000