C语言strcat()库函数的实现

C语言strcat()库函数的实现

#include<stdio.h>
#include<string.h>
void MyStrcat(char *dstStr, char *srcStr)
{
    int a,b,i;
    a=strlen(dstStr);
    b=strlen(srcStr);
    for(i=0;i<b;i++)
    dstStr[a+i]=srcStr[i];
    dstStr[a+b]=0;
}
void main()
{
    char dst[500];
    char src[200];
    printf("Input the first string:");
    gets(dst);
    printf("Input the second string:");
    gets(src);
    MyStrcat(dst,src);
    printf("The result is: %s
",dst);
}

思路:将dst后面的’/0’由src的第一个字符覆盖即可

博客园:https://www.cnblogs.com/newtol 微信公众号:Newtol 【转发请务必保留原作者,否则保留追责权利】
原文地址:https://www.cnblogs.com/newtol/p/10159141.html