mystrcat

#include<stdio.h>
//如果一个数组做为函数的形参传递,那么数组可以在被调用的函数中修改
//有时候不希望这个事发生,所以对形参采用const参数
//size_t strlen(const char *s);
//strcpy(char* s1,const char* s2); 
void mystrcat(char *s1,const char *s2)
{
    int len = 0;
    while(s2[len])
    {
        len++;
    }
    while(*s1)
    {
        s1++;
    }
    int i;
    for(i = 0; i < len; i++)
    {
        *s1 = *s2;
        s1++;
        s2++;
    }
}

int main()
{
    char s1[10] = "123";
    char s2[10] = "456";
    mystrcat(s1,s2);
    printf("s1 = %s
",s1);
    return 0;
} 
原文地址:https://www.cnblogs.com/wanghao-boke/p/11006984.html