我正在 Visual Studio C 中编程。该程序包括监视垄断游戏,我想知道如何从函数传递结构矩阵的值,但它给了我错误 C2106('=' 左运算符必须是 l -值)。
这是我在 main.c 中的代码:
campo = play(gioca, campo, &sortedPlayers, roundPlayer);
/*gioca and roundPlayer are both an int value
* sortedPlayers is a list of struct
* campo[][] is an matrix of struct (is the field of the game)
*/
这是我在头文件中的代码:
casa** play(int scelta, casa campo[DIM_CAMPO][DIM_CAMPO], playerlist* players, int idP);
这是我在 .c 文件中的代码:
casa** play(int scelta, casa campo[DIM_CAMPO][DIM_CAMPO], playerlist* players, int idP) {
int dado1, dado2, isDadoDoppio, idx;
player player;
playerlist copiaPlayers = emptylistP(), defPlayers = emptylistP();
switch (scelta) {
case 0:
exit(0);
break;
case 1:
srand(time(NULL));
dado1 = rand() % 6 + 1;
dado2 = rand() % 6 + 1;
printf("\nIl numero uscito e': %d + %d", dado1, dado2);
if (dado1 == dado2)
isDadoDoppio = 1;
else
isDadoDoppio = 0;
copiaPlayers = *players;
while (!emptyP(copiaPlayers)) {
player = headP(copiaPlayers);
/* Movimento giocatore */
if (player.idP = idP) {
for (idx = 0; idx < dado1 + dado2; idx++) {
//printf("\n[%d][%d] --> ", player.x, player.y);
if (player.x == 0 && (player.y <= 10 && player.y > 0))
player.y += 1;
else if (player.x == 10 && (player.y <= 10 && player.y > 0))
player.y -= 1;
else if (player.y == 0 && (player.x <= 10 && player.x > 0))
player.x -= 1;
else if (player.y == 10 && (player.x <= 10 && player.x > 0))
player.x += 1;
//printf("[%d][%d]", player.x, player.y);
}
break;
}
defPlayers = newPlayer(player, defPlayers);
campo[player.x][player.y].simbolo = (char)player.idP;
copiaPlayers = tailP(copiaPlayers);
}
break;
}
return campo;
}
campo = play(gioca, campo, ...
我敢打赌作业中的
campo
是一个数组。您无法分配数组。
此外,如果将 2D 数组作为参数传递,则无法返回指向指针的指针。数组不是指针!!!