访问2d结构数组的值

时间:2016-03-06 15:16:12

标签: c arrays pointers struct

所以我有这个结构

struct cell
{
    int downwall;
    int rightwall;
};

我已为2d结构单元格数组动态分配内存 (struct cell ** array)

然而,当我尝试使用命令

访问某个单元格时
array[i][j] -> downwall = 0;

我收到此错误:

  

' - >'的无效类型参数(有'struct cell')

5 个答案:

答案 0 :(得分:2)

使用

array[i][j].downwall = 0;

代替。

如果->类型arrray[i][j]不具备struct cell*,您就会使用struct cell。它的类型为System.Data.SQLite reference

答案 1 :(得分:1)

array[i][j]的类型将是struct cell,而不是struct cell *。您应该使用.运算符来访问成员。

你需要写

 array[i][j].downwall = 0;   // use of .

答案 2 :(得分:0)

请注意

struct cell** array

不是2D数组!它是指向“struct cell”类型指针的指针。 只有当值指向(静态或动态)的已分配内存时,才应将其视为2D数组。否则,您正在寻找分段错误。

答案 3 :(得分:0)

您的struct不是指针结构,所以只需执行以下操作:

 $sql = "SELECT * FROM the_DB WHERE barcode = '%$barcode%'";

答案 4 :(得分:-2)

您需要使用正确数量的索引声明一个实际数组,然后使指针指向它。使用键入的名称来帮助(简化的匈牙利表示法)

 int    iAry[M][N];
 int    **ptrAry;

 ptrAry = iAry;    /*  equivalent to ptrAry = &iAry[0][0];    */

 /* then use -> operator as you have done   */
相关问题