2d array, using calloc in C

后端 未结 4 1260
长情又很酷
长情又很酷 2021-01-28 17:54

I\'m trying to create a 2D array of chars to storage lines of chars. For Example:

lines[0]=\"Hello\";
lines[1]=\"Your Back\";
lines[2]=\"Bye\";

4条回答
  •  借酒劲吻你
    2021-01-28 18:13

    No the code is not in a function.

    You can't just put arbitrary statements outside of functions in C and C++. What you can do though is use a function to initialize the variable:

    char** init_lines() {
        char** ln = /* ... */;
        // your allocations etc. here
        return ln;
    }
    
    char** lines = init_lines();
    

提交回复
热议问题