/* Write the copy function to perform exactly as strncpy does, with one
   exception: your copy function will guarantee that dest is always
   null-terminated. Capacity is expected to be the number of bytes of 
   memory allocated to dest.
   You shoud read the man page to learn how strncpy works.

  NOTE: You must write this function without using any string functions.
  The only function that should depend on string.h is memset.
 */ 

char *copy(char *dest, const char *src, int capacity) {
    // Case 1: dest < src; cannot fully copy over, need to null terminate   
    int i;
    for (i = 0; i < capacity && src[i] != '\0'; i++) {
        dest[i] = src[i];
    } 
    for ( ; i < capacity; i++) {
        dest[i] = '\0';}
    
    dest[capacity - 1] = '\0';
    // Case 2: dest > src; have space left in dest
    
    return dest;
}