IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

Incompatible pointer erreur bizzare


Sujet :

C

  1. #1
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Août 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 23
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Août 2016
    Messages : 3
    Points : 3
    Points
    3
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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]);

  2. #2
    Membre émérite
    Homme Profil pro
    sans emploi
    Inscrit en
    Janvier 2014
    Messages
    539
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Janvier 2014
    Messages : 539
    Points : 2 601
    Points
    2 601
    Par défaut
    Bonjour,
    tu mélanges des int [MATRIX_Y][MATRIX_X] avec des int [MATRIX_X][MATRIX_Y]. Quand les deux dimensions sont égales il n'y a a pas de problèmes : une matrice 3×3 reste une matrice 3×3 qu'on commence par ligne ou les colonnes ; quand elles sont différentes tu n'as plus le même type car une matrice 5xx10 est différente d'une matrice 10×5.

  3. #3
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Août 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 23
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Août 2016
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    HAHAHA cette erreur je suis vraiment inattentif

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Incompatible pointer type
    Par Spinoza23 dans le forum Débuter
    Réponses: 12
    Dernier message: 27/05/2008, 15h34
  2. erreur bizzare !
    Par lektrosonic dans le forum Débuter
    Réponses: 2
    Dernier message: 03/12/2007, 13h53
  3. Réponses: 9
    Dernier message: 21/10/2006, 13h38
  4. [C::B-Linux] Erreur bizzare
    Par Goundy dans le forum C
    Réponses: 16
    Dernier message: 03/04/2006, 16h12
  5. Question facile, erreur bizzare lors d'un Left, Top
    Par SpiderAlpha dans le forum C++Builder
    Réponses: 4
    Dernier message: 05/05/2004, 12h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo