Getting Segmentation Fault

后端 未结 5 1962
我寻月下人不归
我寻月下人不归 2020-11-27 19:21

I saw many questions about getting segmentation fault in C program here in SO, and I thought it would be great to have a reference to those here, a question

5条回答
  •  情话喂你
    2020-11-27 19:35

    1. You have not allocated any memory. *str is just a pointer.
    2. Reason for the segfault is in line 2, you need to malloc strlen() + 1 because of the string delimiter '\0'

提交回复
热议问题