How to properly use scandir() in c?

前端 未结 4 870
独厮守ぢ
独厮守ぢ 2021-02-06 10:42

I am trying to store list of files in a char** variable.

scandir() finishes properly but I get a segmentation fault when trying to print the char**.

Here\'s the co

4条回答
  •  遇见更好的自我
    2021-02-06 11:16

    I am not sure this is the problem, but you have to allocate another byte for the null termination:

    *fileList[i] = (char*)malloc(strlen(fileListTemp[i] -> d_name + 1) *sizeof(char));
    

提交回复
热议问题