String concatenation without strcat in C

前端 未结 7 773
伪装坚强ぢ
伪装坚强ぢ 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:43

    You can do it using strcpy() too ;)

    char *a = (char *) malloc(100);
    char *b = (char *) malloc(100);
    
    strcpy(a, "abc");               // initializes a
    strcpy(b, "def");               // and b
    
    strcpy((a + strlen(a)), b);     // copy b at end of a
    
    printf("%s\n",a);               // will produce: "abcdef"
    

提交回复
热议问题