模拟实现strncat():
    与函数strcat()有区别,是防止当自己连接自己时找不到'\0'无法连接。而关于strcat()函数可见博客连接     
 
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
char *my_strncat(char *dest, char *src, int len)
{
    assert(dest);
    assert(src);
    char *ret = dest;
    while (*dest)
    {
        dest++;
    }
    while (len--)
    {
        *dest = *src;
        dest++;
        src++;
    }
    *dest = '\0';
    return ret;
}

int main()
{
    char arr[20] = "hello ";
    int len = strlen(arr);
    char *ret = my_strncat(arr, arr, len);
    printf("%s", ret);
    system("pause");
    return 0;
}