Skip to main content

Practice ยท 1 of 2

Three-Valued APIs

Implement the discriminating API. The boilerplate declares: ``c #define LOOKUP_FOUND 0 #define LOOKUP_ABSENT 1 #define LOOKUP_ERROR (-1) typedef struct { long keys[16]; long vals[16]; size_t n; } Table; void tab_init(Table *t); int tab_put(Table *t, long k, long v); /* 0 ok, -1 full/NULL */ /* FOUND (fills *out) | ABSENT | ERROR (bad args) */ int tab_get(const Table *t, long k, long *out); int tab_del(Table *t, long k); /* 1 removed, 0 absent, -1 NULL */ `` The tests distinguish all three values โ€” a conflation fails them.

Difficulty: intermediate

Back to lesson: Practice: Error Contract Gym