The snippet library.
Small, practical examples. Search by task or narrow things down below.
Read text in bounded chunks
Read a C text file with fgets and a fixed buffer.
C✓ Tested
Read the beginning of a text value
C: Extract or display the first three ASCII characters from a known nonempty string.
C✓ Tested
Read the first collection element
C: Access index zero only after establishing that the collection is nonempty.
C✓ Tested
Reject NaN and infinite values
C: isfinite detects whether a floating-point value is an ordinary finite number.
C✓ Tested
Remove a trailing line ending
Use strcspn to terminate a C string at its first newline or carriage return.
C✓ Tested
Remove adjacent duplicates from a sorted array
C: Compact equal neighbors with a write index after sorting or otherwise establishing order.
C✓ Tested
Remove one array element and close the gap
C: memmove handles the overlap while the logical length shrinks by one.
C✓ Tested
Remove one known scratch file
C: Check remove’s return value instead of assuming deletion succeeded.
C✓ Tested
Rename a known file
C: The standard rename function reports failure through its return value.
C✓ Tested
Repeat a fixed number of times
C: Use a counted loop to print three numbered steps.
C✓ Tested
Repeat while a condition holds
C: Count down while a positive number remains, updating the loop variable on each iteration.
C✓ Tested
Replace bytes at a known position in a binary file
C: Open in update mode and seek before writing a fixed-size replacement.
C✓ Tested