String concatenation without strcat in C

前端 未结 7 768
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 13:44

I am having trouble concatenating strings in C, without strcat library function. Here is my code

#include
#include
#include<         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 14:44

    i think this is an easy one.

    #include
    int xstrlen(char *);
    void xstrcat(char *,char *,int);
    void main()
    {
        char source[]="Sarker";
        char target[30]="Maruf";
        int j=xstrlen(target);
        xstrcat(target,source,j);
        printf("Source String: %s\nTarget String: %s",source,target);
    }
    int xstrlen(char *s)
    {
        int len=0;
        while(*s!='\0')
        {
            len++;
            s++;
        }
        return len;
    }
    void xstrcat(char *t,char *s,int j)
    {
        while(*t!='\0')
        {
            *t=*t;
            t++;
        }
        while(*s!='\0')
        {
            *t=*s;
            s++;
            t++;
        }
    }
    

提交回复
热议问题