C语言实现strcat

代码

#include 
#include 

char * mystrcat(char *dest,const char * src)
{
        assert( (dest != NULL) && (src != NULL));
        char * p = dest;
        while( *dest != '\0')
                dest++;
        while( (*dest++ = *src++) != '\0');
        return p;

}



int main()
{
        char str1[10] = "abc";
        char str2[] = "defg";
        printf("%s\n",mystrcat(str1,str2));

        return 0;
}

执行

abcdefg

 

你可能感兴趣的:(C)