FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
CStrings & byte buffers

Move overlapping bytes safely

C: memmove supports overlapping ranges, unlike memcpy.

C✓ Tested
CGetting Started

Name a value that stays fixed

C: Use a constant declaration or the language’s constant naming convention for a fixed limit.

C✓ Tested
CBinary formats & structured parsing

Parse a bounded simple record with sscanf

C: A width limit protects the destination buffer and the consumed count detects trailing junk.

C✓ Tested
CNumbers & memory

Parse an integer with validation

Validate range and trailing characters when parsing a C integer with strtol.

C✓ Tested
CNumeric parsing & arithmetic

Parse an unsigned hexadecimal integer

C: Use an explicit base and check both range and full consumption.

C✓ Tested
CStructures & function interfaces

Pass a function as a callback

C: A typed function pointer permits behavior to be supplied to another function.

C✓ Tested
CGetting Started

Print a number with two decimal places

C: Format a small decimal value consistently for display.

C✓ Tested
CBinary formats & structured parsing

Quote a CSV field and double embedded quotes

C: A quoted CSV field represents a quote character by repeating it.

C✓ Tested
CFile positioning & lifecycle

Read a stream again from its beginning

C: rewind returns a seekable stream to offset zero and clears its error and EOF indicators.

C✓ Tested
CFile positioning & lifecycle

Read bytes from a chosen file offset

C: Check fseek before reading so an unsupported or invalid seek is not ignored.

C✓ Tested
CFile positioning & lifecycle

Read characters without confusing EOF with a byte

C: Store fgetc in int so every unsigned-char value remains distinguishable from EOF.

C✓ Tested
CGetting Started

Read one character from ASCII text

C: Use a valid zero-based index to read the first character.

C✓ Tested