Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C:下标值既不是数组也不是指针_C_Arrays - Fatal编程技术网

C:下标值既不是数组也不是指针

C:下标值既不是数组也不是指针,c,arrays,C,Arrays,我试图创建一个函数来初始化一个Othero游戏的棋盘,我认为使用通用函数会更好地学习,但我很早就遇到了问题,有人能告诉我为什么这不起作用吗? 我定义了一个othelotype,它是一个10x10 int数组 othelotype* inicializartablero (othelotype* board) { int x, y; for (x = 0; x < 8; x++) for (y = 0; y < 8; y++) board[x][y] =

我试图创建一个函数来初始化一个Othero游戏的棋盘,我认为使用通用函数会更好地学习,但我很早就遇到了问题,有人能告诉我为什么这不起作用吗? 我定义了一个othelotype,它是一个10x10 int数组

othelotype* inicializartablero (othelotype* board)
{
  int x, y;

  for (x = 0; x < 8; x++)
    for (y = 0; y < 8; y++)
       board[x][y] = 2;


  board[4][5] = board[5][4] = 0;
  board[4][4] = board[5][5] = 1;

}
OtheroType*inicializartablero(OtheroType*板)
{
int x,y;
对于(x=0;x<8;x++)
对于(y=0;y<8;y++)
董事会[x][y]=2;
董事会[4][5]=董事会[5][4]=0;
董事会[4][4]=董事会[5][5]=1;
}

根据您评论中的代码,
OtheroType
不是10x10数组-它是一个结构。无法使用
[]
运算符访问结构。您可以使用结构访问其成员。在本例中,我假设您希望访问
cuadrado
成员,然后索引到该成员(因为它实际上是一个数组)。

您可以继续使用
otheroType*board
作为参数,您只需使用
board->cuadrado>访问其中的实际数组即可:

othelotype* inicializartablero (othelotype* board)
{
  int x, y;

  for (x = 0; x < 8; x++)
    for (y = 0; y < 8; y++)
       board->cuadrado[x][y] = 2;


  board->cuadrado[4][5] = board->cuadrado[5][4] = 0;
  board->cuadrado[4][4] = board->cuadrado[5][5] = 1;

}
OtheroType*inicializartablero(OtheroType*板)
{
int x,y;
对于(x=0;x<8;x++)
对于(y=0;y<8;y++)
线路板->cuadrado[x][y]=2;
board->cuadrado[4][5]=board->cuadrado[5][4]=0;
board->cuadrado[4][4]=board->cuadrado[5][5]=1;
}

你能告诉我们
otheroType的定义吗
?它是下面的结构otheroType{int cuadrado[10][10];}*board2;通常最好将
struct-otherotype{…}解耦来自变量定义。另外,当您不需要动态分配时,您可以使用
struct otherotype board
,然后将其传递给您的函数
inicializartablero(&booard)
。那么函数应该接收cuadrado吗?我的想法是保持模块化,但我对语法不太熟悉。你可以简单地接收
otherotype
,然后用它访问
cuadrado
。请看我的新答案。谢谢,这正是我的意思,游标的使用对我来说是全新的。