#include <iostream>
using namespace std;

unsigned int str_len(const char* s)
{
    if (!s) throw invalid_argument("nullptr in str_len()");
    unsigned int l = 0;
    while(*s++) ++l;
    return l;
}

char* str_n_cat(char* dest, const char* source, unsigned int num)
{
    if (!dest || !source) return nullptr;
    char * t = dest + str_len(dest);
    while(num-- && (*t++ = *source++));
    if (num == 0) *t = 0;
    return dest;
}

int main()
{
    for(int n = 0; n < 10; ++n)
    {
        char s[20] = "dest";
        char m[]   = "source";
        cout << "[" << str_n_cat(s, m, n) << "]\n";
    }
}
