Using C-string gives Warning: “Address of stack memory associated with local variable returned”

后端 未结 4 1789
你的背包
你的背包 2020-12-08 06:52

I am not a C programmer, so I am not that familiar with C-string but now I have to use a C library so here is a shortened version of my code to demonstrate my problem:

<
4条回答
  •  不知归路
    2020-12-08 07:20

    Use heap instead of stack

    It's better to allocate memory in heap for this case by using:

    int* someDataForParams(void *_params) {
    
        ...
        int* charCounts = calloc(96, sizeof(char*));
        ...
    
        return charCounts;
    }
    

    96 is just a string length(Just a magic number)

提交回复
热议问题