Insert a string into another string efficiently

后端 未结 4 1823
清歌不尽
清歌不尽 2021-01-07 05:10

I have

char aa[] = { \"Hello, !\" };

char bb[] = { \"World\" };

How to insert bb into aa the most efficiently with cstring

4条回答
  •  孤城傲影
    2021-01-07 05:32

    char *newStr = malloc(strlen(aa) + strlen(bb));

    sprintf(newStr, "%s%s", aa, bb);

提交回复
热议问题