Malloc compile error: a value of type “int” cannot be used to initialize an entity of type int (*)[30]

前端 未结 6 682
小鲜肉
小鲜肉 2020-12-03 11:56

I must have tried 20 ways of doing this by now. I really need help, no matter what I do i get a error similar to this one.

a value of type \"int\" cannot be          


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 12:08

    2D array to store char *

    char ***array;
    int rows = 2, cols = 2, i, j;
    array = malloc(sizeof(char **)*rows);
    for (i = 0; i < rows; i++)
      array[i] = malloc(cols * sizeof(char *));
    
    array[0][0] = "asd";
    array[0][1] = "qwe";
    array[1][0] = "stack";
    array[1][1] = "overflow";
    
    for(i=0;i

提交回复
热议问题