Skip to main content

Practice ยท 3 of 4

Every Path Frees

Implement a function with MULTIPLE allocation and failure paths where every path balances: ``c /* builds "N=x;D=y" from two ints using two temp buffers; on any failure returns 0 with *out untouched; on success returns 1, caller frees *out. */ int format_stats(int n, double d, char **out); `` Use snprintf into a heap buffer per half, then join. The point of the exercise: if the second allocation fails, the first must be freed.

Difficulty: intermediate

Back to lesson: Practice: Failure-Path Gym