FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
CArray transformations

Sort an integer array with qsort

C: The comparator uses relational comparisons to avoid subtraction overflow.

C✓ Tested
CStrings & byte buffers

Split simple delimited text in place

C: strtok inserts terminators into a writable buffer and skips repeated delimiter characters.

C✓ Tested
CGetting Started

Store a value in a named variable

C: Give a value a descriptive name and print it.

C✓ Tested
CDynamic memory & ownership

Store a variable-length payload after a structure header

C: A flexible array member lets one allocation hold metadata and trailing bytes.

C✓ Tested
CArrays

Sum array values

Iterate over a fixed C array using a size-derived element count.

C✓ Tested
CSmall algorithms & bit operations

Sum the decimal digits of an unsigned integer

C: Repeated division and remainder extract digits without converting to text.

C✓ Tested
CDynamic memory & ownership

Swap owned buffers by swapping their pointers

C: Pointer swaps avoid copying the underlying data.

C✓ Tested
CNumbers & memory

Swap two integers

Use a temporary value to swap C integers without arithmetic overflow.

C✓ Tested
CSmall algorithms & bit operations

Test whether an unsigned value is a power of two

C: A nonzero power of two has exactly one set bit.

C✓ Tested
CStructures & function interfaces

Track which union member is currently valid

C: An explicit tag tells callers which overlaid union value to read.

C✓ Tested
CGetting Started

Update a running count

C: Change a variable after its initial value has been assigned.

C✓ Tested
CFile positioning & lifecycle

Use an automatically removed temporary file

C: tmpfile creates a binary update stream whose file is removed when closed.

C✓ Tested