Skip to main content

Practice ยท 2 of 2

Build the Growable String

Implement the StrBuf from the lesson. The boilerplate declares: ``c typedef struct { char *data; size_t len; size_t cap; } StrBuf; void sb_init(StrBuf *b); /* empty but valid; data may be NULL */ int sb_append(StrBuf *b, const char *s); /* 0 ok, -1 bad args/oom */ void sb_free(StrBuf *b); /* ends ownership, back to init state */ ` After append, data must be a valid ''-terminated string of len characters with room for at least len + 1` bytes.

Difficulty: intermediate

Back to lesson: Practice: Safe Copy Gym