basics · beginner · ~10 min
ASCII-only case folding without external dependencies.
Implement void to_lower_ascii(char *s) that converts every uppercase ASCII letter ('A'..'Z') in s to its lowercase equivalent, in place. All other bytes are left unchanged.
"HELLO" -> "hello"
"Hello, X!" -> "hello, x!"
"123abcXYZ" -> "123abcxyz"
"" -> ""
Case-folding is the canonical 'normalise this string' step in URL handling, header parsing, command matching, and search. ASCII-only folding is the safe baseline; full Unicode case-folding is a much harder problem.
Null-terminated mutable ASCII string.
s is mutated in place.
O(strlen). Pure ASCII — do not touch non-ASCII bytes.
void to_lower_ascii(char *s) { /* TODO */ }
Using tolower without the unsigned char cast — undefined behaviour for high-bit bytes. Touching every byte (corrupts UTF-8 continuation bytes that happen to fall in the range 0x41-0x5A in a multi-byte sequence — actually UTF-8 continuation bytes are 0x80+, so this is safe with the ASCII guard).
Empty string; already-lowercase string; mixed with digits and punctuation; high-bit bytes (must passthrough).
O(strlen(s)).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.