Skip to main content

Practice ยท 1 of 4

A Safe Comparator

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).

Difficulty: intermediate

Back to lesson: Practice: Comparator Gym