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的第一个字符覆盖即可