-4

when i compile i don't know why the display function doesn't work the function name "affichage_plateau()" Well I will want to create a game of chess but I am just a beginner in c language, I spent all day trying to understand why the display function does not show me the elements of the board, I have consult several forums I looked for ask friends but I still can not find the solution, so please if anyone has a little idea why the function is not displayed please help me :)


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


#define LIG 8
#define COL 8

int **plateau(void);
void affichage_plateau(int **tab);


int main(void){

  int ch;
  int **ech = plateau();

  printf("----------------------------------------------------------------------\n");
  printf("|Essai D'un Jeu d'echec :                                            |\n");
  printf("|                             BienVenue                              |\n");
  printf("|                                                                    |\n");
  printf("|        Ce programme a ete realise avec soin par :                  |\n");
  printf("|                                                                    |\n");
  printf("|                                                                    |\n");
  printf("----------------------------------------------------------------------\n");
  printf("\n");
  do{
    printf("---------------Tapez 1 pour Jouer---------------\n");
    printf("---------------Tapez 2 pour afficher les regles-\n");
    printf("---------------Tapez 3 pour quittez-------------\n");
    printf("\nVotre choix :\t");
    scanf("%d",&ch);
    switch(ch){
      case 1 :
        printf("Jouer :)");
        break;
      case 2 :
        printf("Rules :)\n");
        printf("Affichage :\n");
        affichage_plateau(ech);
        break;
      case 3 :
        printf("Good Bye :)");
        break;
    }
  }while(ch<1 || ch>3);
  return EXIT_SUCCESS;
}
int **plateau(void){
  int i , j ;
  int k = 1 ;
  static int ec[LIG][COL];
  for(i = 0 ; i < LIG ; i++){
    for(j = 0 ; j < COL ; j++){
      ec[i][j] = k;
      k++;
    }
  }
  return (void *)ec;
}
// i have the probleme here
void affichage_plateau(int **tab){
    int i ;
    int j ;
    for(i = 0 ; i < LIG ; i++){
      for(j = 0 ; j < COL ; j++){
        printf("ec[%d][%d] = %d \n",i,j,tab[i][j]);
      }
    }
}



Yahya Ben
  • 15
  • 1

1 Answers1

3

You hammered an undefined cast through via (void *).

static int ec[LIG][COL]; is not compatible with int **tab. You want this:

int (*plateau(void))[COL], int *ech[COL] = plateau(); and affichage_plateau(int *tab[COL])

Joshua
  • 40,822
  • 8
  • 72
  • 132