Skip to main content

Practice ยท 1 of 2

A Copy That Reports Truncation

Implement the copy family that never lies: ``c /* copies src into dst (capacity dstcap). Always ''-terminates when dstcap > 0. Returns: 0 if src + its '' fit (exact fit), 1 copied-but-truncated, -1 bad args (dst NULL, dstcap == 0, or src NULL). src == dst returns 0. */ int copy_bounded(char *dst, size_t dstcap, const char *src); /* like copy_bounded but only the length that WOULD be needed (excluding ''); 0 for NULL src */ size_t copy_needed(const char *src); ``

Difficulty: intermediate

Back to lesson: Practice: Safe Copy Gym