cybersecurity · beginner · ~15 min
Check capacity before appending.
Implement int append_pos(int curlen, int addlen, int cap) returning the offset to append at if curlen + addlen fits in cap (leaving room for a NUL: curlen + addlen < cap), else -1.
int append_pos(int curlen, int addlen, int cap) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.