strcat concat a char onto a string?

后端 未结 6 741
谎友^
谎友^ 2020-12-14 22:45

Using GDB, I find I get a segmentation fault when I attempt this operation:

strcat(string,¤tChar);

Given that string is initializ

6条回答
  •  我在风中等你
    2020-12-14 23:18

    The first argument of strcat must have enough space to hold the rest of the string. "" is a constant string and as such GCC does not allocate space.

    Make it an array with enough space:

    char buf[1024];
    
    strcat(buf, "");
    strcat(buf, "B");
    

提交回复
热议问题