Skip to main content

Practice · 1 of 4

A Safe Comparator

CHALLENGE
Difficulty: intermediate+25 XP

Implement the overflow-proof comparator family: ``c int cmp_int(const void *a, const void *b); /* ints ascending */ int cmp_long(const void *a, const void *b); /* longs ascending */ int cmp_str(const void *a, const void *b); /* C strings ascending (strcmp) */ `` All three follow the qsort contract. cmp_str receives pointers to char* (the array elements are char* values).

Back to lesson: Practice: Comparator Gym