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

前端 未结 6 674
小鲜肉
小鲜肉 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:00

    Don't mind me I'm just adding an example using calloc

    void allocate_fudging_array(int R, int C)
    {
        int **fudging_array = (int **) calloc(R, sizeof(int *));
        for(int k = 0; k < R; k++)
        {
            fudging_array[k] = (int*) calloc(C, sizeof(int));
        }
    }
    
    
    // a helper function to print the array 
    void print2darr(int **arr, int R, int C)
    {
        for(int i = 0; i < R; i++)
        {
            for(int j = 0; j < C; j++)
            {
                printf(" %d  ", arr[i][j]);
            }
            printf("\n");
        }
    }
    

提交回复
热议问题