Dynamic 2D array in typedef

前端 未结 2 366
自闭症患者
自闭症患者 2021-01-28 08:09

How do I get this to work? I am not sure how many invoices a customer will be assigned to and want to leave it dynamic. Please help.

#include 
#in         


        
2条回答
  •  逝去的感伤
    2021-01-28 08:52

    You can change invoices to int** invoices and then allocate dynamically using malloc(). You can allocate a 2D array like this:

    int** theArray;
    theArray = (int**) malloc(arraySizeX*sizeof(int*));
    for (int i = 0; i < arraySizeX; i++)
       theArray[i] = (int*) malloc(arraySizeY*sizeof(int));
    

提交回复
热议问题