Skip to main content

Practice ยท 4 of 4

A Table That Takes Ownership

Implement a string table that OWNS its entries: ``c typedef struct { char **items; size_t len, cap; } OwnedTable; /* in boilerplate */ void ot_init(OwnedTable *t); /* copies s into fresh memory and stores it. 0 on failure (t unchanged). */ int ot_add(OwnedTable *t, const char *s); /* number of entries currently stored */ size_t ot_len(const OwnedTable *t); /* frees every string AND the array; zeroes the struct */ void ot_destroy(OwnedTable *t); /* removes the last entry, frees it, returns 1; 0 if empty */ int ot_pop(OwnedTable *t); ``

Difficulty: intermediate

Back to lesson: Practice: Failure-Path Gym