Incompatible pointer erreur bizzare
Bonjour, a tous
Je vous explique le topo je tente de coder un morpion au debut j'ai mis en coordonner X 3 et Y 3 dans mais constante #define MATRIX_X et #define MATRIX_Y
Or des que je change ces valeur pour aggrandir le tableau le compilateur gcc me montre une suite d'erreur qu'il n'y avait pas si je metters 3 et 3 dans la #define
Je voudrais votre aide car je ne voit pas d'où l'erreur peut venir :/
Tout le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
/**************************************************
* #DEFINE DECLARATION *
***************************************************/
#define MATRIX_X 10
#define MATRIX_Y 5
#define MATRIX_DEFAULT_VALUE 0
/***************************************************
* STRUCT & ENUM DECLARATION *
****************************************************/
typedef struct Position Position;
typedef struct Player Player;
typedef enum Boolean bool;
struct Position
{
int x;
int y;
};
struct Player
{
Position playerPosition;
int score;
char player;
};
enum Boolean
{
false,
true
};
/* MOVEMENT IN MATRIX */
int left(int x);
int right(int x);
int up(int y);
int down(int y);
void keyIsPressed(Player *player, int array2D[MATRIX_Y][MATRIX_X]);
/* INIT */
void matrixInitInvisible(int array2D[MATRIX_X][MATRIX_Y]);
void showMatrix(int array2D[MATRIX_X][MATRIX_Y]);
Player initPlayer(const char character);
int main(void)
{
int matrixMap[MATRIX_Y][MATRIX_X] = {MATRIX_DEFAULT_VALUE};
bool crossPlay = false;
Player cross = initPlayer('X');
Player round = initPlayer('O');
matrixInitInvisible(matrixMap);
matrixMap[MATRIX_X / 2][MATRIX_Y/2] = cross.player;
crossPlay = true;
while(true)
{
if (crossPlay == true)
{
printf("%s\n", "\t\tCross Player Play!");
keyIsPressed(&cross, matrixMap);
matrixMap[cross.playerPosition.y][cross.playerPosition.x] = cross.player;
}
else if (crossPlay == false)
{
}
showMatrix(matrixMap);
Sleep(100);
system("cls");
}
return EXIT_SUCCESS;
}
/* MOVEMENT IN MATRIX */
int left(int x)
{
return x-1;
}
int right(int x)
{
return x+1;
}
int up(int y)
{
return y-1;
}
int down(int y)
{
return y+1;
}
/* INIT */
void matrixInitInvisible(int array2D[MATRIX_X][MATRIX_Y])
{
Position position;
for(position.y = 0; position.y < MATRIX_Y; position.y ++)
{
for(position.x = 0; position.x < MATRIX_X; position.x ++)
{
array2D[position.y][position.x] = MATRIX_DEFAULT_VALUE;
}
}
}
void showMatrix(int array2D[MATRIX_X][MATRIX_Y])
{
Position position;
for(position.y = 0; position.y < MATRIX_Y; position.y ++)
{
for(position.x = 0; position.x < MATRIX_X; position.x ++)
{
printf("%c", array2D[position.y][position.x]);
}
putchar('\n');
}
}
Player initPlayer(const char character)
{
Player newPlayer;
newPlayer.playerPosition.x = 0;
newPlayer.playerPosition.y = 0;
newPlayer.score = 0;
newPlayer.player = character;
return newPlayer;
}
void keyIsPressed(Player *player, int array2D[MATRIX_Y][MATRIX_X])
{
if(GetAsyncKeyState(VK_LEFT))
{
printf("CROSS PLAYER POSITION MOVE LEFT\n");
array2D[player->playerPosition.y][player->playerPosition.y] = MATRIX_DEFAULT_VALUE;
player->playerPosition.x = left(player->playerPosition.x);
}
else if(GetAsyncKeyState(VK_RIGHT))
{
printf("CROSS PLAYER POSITION MOVE RIGHT\n");
array2D[player->playerPosition.y][player->playerPosition.y] = MATRIX_DEFAULT_VALUE;
player->playerPosition.x = right(player->playerPosition.x);
}
else if (GetAsyncKeyState(VK_UP))
{
printf("CROSS PLAYER POSITION MOVE UP\n");
array2D[player->playerPosition.y][player->playerPosition.y] = MATRIX_DEFAULT_VALUE;
player->playerPosition.y = up(player->playerPosition.y);
}
else if(GetAsyncKeyState(VK_DOWN))
{
printf("CROSS PLAYER POSITION MOVE DOWN\n");
array2D[player->playerPosition.y][player->playerPosition.y] = MATRIX_DEFAULT_VALUE;
player->playerPosition.y = down(player->playerPosition.y);
}
} |
Erreur GCC
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
main.c:49:6: note: expected 'int (*)[5]' but argument is of type 'int (*)[10]'
void matrixInitInvisible(int array2D[MATRIX_X][MATRIX_Y]);
^
main.c:79:16: warning: passing argument 1 of 'showMatrix' from incompatible pointer type
showMatrix(matrixMap);
^
main.c:50:6: note: expected 'int (*)[5]' but argument is of type 'int (*)[10]'
void showMatrix(int array2D[MATRIX_X][MATRIX_Y]);
^
C:\Users\samue\Desktop\Morpion>gcc main.c -o prog
main.c: In function 'main':
main.c:62:23: warning: passing argument 1 of 'matrixInitInvisible' from incompatible pointer type
matrixInitInvisible(matrixMap);
^
main.c:49:6: note: expected 'int (*)[5]' but argument is of type 'int (*)[10]'
void matrixInitInvisible(int array2D[MATRIX_X][MATRIX_Y]);
^
main.c:79:16: warning: passing argument 1 of 'showMatrix' from incompatible pointer type
showMatrix(matrixMap);
^
main.c:50:6: note: expected 'int (*)[5]' but argument is of type 'int (*)[10]'
void showMatrix(int array2D[MATRIX_X][MATRIX_Y]); |