Segmentation fault using strcat

前端 未结 5 1632
孤独总比滥情好
孤独总比滥情好 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条回答
  •  执笔经年
    2020-12-04 03:49

    the name_log is pointed at a static place: "log-", which means is could not be modified, while as the first parameter in strcat(), it must be modifiable.

    try changing name_log's type char* into char[], e.g.

    char[20] name_log = "log-";
    

提交回复
热议问题