char *copy(char *dest, const char *src, int capacity) {
 16
 17     int i;
 18     for (i = 0; i < capacity && src[i] != '\0'; i++) {
 19         dest[i] = src[i];
 20     }
 21
 22     for (; i < capacity; i++) {
 23         dest[i] = '\0';
 24     }
 25
 26     return dest;
 27 }
This should work just the same as strncpy