char *copy(char *dest, const char *src, int capacity) {
  int null_count = 0;
  for (int i = 0; i < capacity; i++) {
    if (src[i] == '\0') { // When src is less than or equal to capacity to be copied
      null_count += (capacity - i);
      break;
      }
    }
  
  if (null_count != 0) {
    for (int j = 0; j < capacity - null_count; j++) {
      dest[j] = src[j];
    }
    for (int k = capacity - null_count; k < capacity; k++) {
      dest[k] = '\0';
    }
  }

  else {
     for (int j = 0; j < capacity - 1; j++) {
       dest[j] = src[j];
     }
    dest[capacity - 1] = '\0';
  }
  for (int i = 0; i < capacity && src[i] != '\0'; i++) {
    dest[i] = src[i];
    for ( ; i < capacity; i++) {
      dest[i] = '\0';
    }
  }
  return dest;
}
