strcat implementation

前端 未结 5 1152
暖寄归人
暖寄归人 2020-12-15 00:22

I tried to implement the strcat by myself, and I found the strcat implementation from Wiki like this......but when I use it, there is segmentation fault.

What\'s wro

5条回答
  •  旧巷少年郎
    2020-12-15 01:27

    Its working fine with me, I have check it.

        #include "stdio.h"
    
    
        char *strcat(char *dest, const char *src)
    
        {
    
        size_t i,j;
    
        for (i = 0; dest[i] != '\0'; i++)
    
            ;
    
        for (j = 0; src[j] != '\0'; j++)
    
            dest[i+j] = src[j];
    
        dest[i+j] = '\0';
    
        return dest;
    
    }
    
    
    void main(void)
    
    {
    
        char a[10]={"abc"}, b[10]={"def"};
    
        strcat(a,b);
    
        printf("%s",a);
    
        getchar();
    
    }
    

提交回复
热议问题