How to concat two char * in C?

后端 未结 3 363
谎友^
谎友^ 2021-01-11 14:19

I receive a char * buffer which have the lenght of 10. But I want to concat the whole content in my struct which have an variable char *.

typedef struct{
            


        
3条回答
  •  孤街浪徒
    2021-01-11 14:42

    You can use strcat(3) to concatenate strings. Make sure you have allocated enough space at the destination!

    Note that just calling strcat() a bunch of times will result in a Schlemiel the Painter's algorithm. Keeping track of the total length in your structure (or elsewhere, if you prefer) will help you out with that.

提交回复
热议问题