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

来源:互联网 发布:法国交友软件 编辑:程序博客网 时间:2024/05/21 19:42

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\n",dst);}

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

原创粉丝点击