cybersecurity · intermediate · ~15 min
Append without overflowing.
Implement int safe_cat(char *dst, int dstsz, const char *src) appending src to dst without exceeding dstsz-1 bytes, always NUL-terminating. Return 0 if it fit, -1 if truncated.
#include <string.h>
int safe_cat(char *dst, int dstsz, const char *src) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.