Results for “extra”
Small, practical examples. Search by task or narrow things down below.
Count matching values
Count even numbers in a fixed C array.
C✓ Tested
Count newline characters
Count newline bytes in a C file while retaining EOF as an int.
C✓ Tested
Count occurrences in a sorted sequence
C++: equal_range finds the half-open interval containing values equal to the key.
C++✓ Tested
Count set bits in an unsigned integer
C: Clearing the lowest set bit on each iteration counts only one iteration per set bit.
C✓ Tested
Count the items in a collection
C++: Read the collection’s length instead of hard-coding the loop limit.
C++✓ Tested
Count the items in a collection
C: Read the collection’s length instead of hard-coding the loop limit.
C✓ Tested
Count word frequencies
Accumulate word counts in an ordered C++ map.
C++✓ Tested
Create an independent copy of a byte buffer
C: Allocate the exact byte length and copy only after checking the result.
C✓ Tested
Create nested directories
Use C++17 filesystem to create a directory tree.
C++✓ Tested
Decode a 16-bit big-endian integer
C: Promote bytes to an unsigned integer type before combining shifted values.
C✓ Tested
Decode a validated pair of hexadecimal digits
C: Convert each nibble and reject a nonhexadecimal character before combining them.
C✓ Tested
Delete one known scratch file
C++: filesystem::remove reports whether an item was removed and also supports empty directories.
C++✓ Tested