Segmentation fault using strcat

前端 未结 5 1631
孤独总比滥情好
孤独总比滥情好 2020-12-04 03:16

Here is my code :

char *name, name_log=\"log-\";

------getting \'name\' from user-----

strcat(name_log, name);
char ext[] =         


        
5条回答
  •  -上瘾入骨i
    2020-12-04 04:05

    you need to allcocate memory. You cannot add to a string in this way as the string added goes to memory which hasnt been allocated.

    you can do

    char[20] strarray;
    
    strcat(strarray, "log-");
    strcat(strarray, "abcd");
    

提交回复
热议问题