Skip to content

Posts

C Basics: Validate Argument Count Before Reading Values

Check argc and a required option name before using argv while keeping shell metacharacters as data.

Read more →

November 1, 2026

C Basics: Validate an Entire Decimal Number with strtol

Check syntax, overflow, trailing characters, and an application range before using a number.

Read more →

November 1, 2026

C Basics: Update Independent Options with Unsigned Bit Masks

Set, clear, toggle, and test option bits without confusing any-bit and all-bit checks.

Read more →

November 1, 2026

C Basics: Switch an Update Stream Between Reading and Writing

Use fseek and ftell to make read and write positions explicit on a temporary binary stream.

Read more →

November 1, 2026

C Basics: Sort Integers Without Comparator Overflow

Use relational comparisons in qsort rather than subtracting values that may overflow.

Read more →

November 1, 2026

C Basics: Separate Read-Only Access from Fixed Pointer Bindings

Compare a pointer-to-const with a const pointer while keeping the underlying object valid.

Read more →

November 1, 2026

C Basics: Remove Line Endings Without Trimming Spaces

Use strcspn to find CR or LF in a writable null-terminated string while preserving other whitespace.

Read more →

November 1, 2026

C Basics: Reject Oversized Lines Without Losing the Next Record

Detect a full fgets buffer, discard the rest of an oversized line, and preserve the next record.

Read more →

November 1, 2026

C Basics: Pass State to a Callback Without Global Variables

Use a function pointer and a context pointer to accumulate values during a visit.

Read more →

November 1, 2026

C Basics: Pass Array Lengths Explicitly to Functions

Calculate an array element count where the array is declared and pass it alongside its pointer.

Read more →

November 1, 2026