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 :

probleme lors de la compilation


Sujet :

C

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    Points : 45
    Points
    45
    Par défaut probleme lors de la compilation
    j'ai inseré un if vers la fin de mon code pour choisir entre noir ou blanc:
    main.c
    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
    #include <stdio.h>
    #include <stdlib.h>
    int c=0;
    int i,j;
    unsigned char p[19][19];  /* go board */
    unsigned char l[19][19];  /* liberty of current color */
    unsigned char ma[19][19]; /* working matrix for marking */
    unsigned char ml[19][19]; /* working matrix for marking */
    char ans[2];
    int p1move, p2move;        /* p1 color, p2 color */
    int lib;                  /* current stone liberty */
    int p1ik, p1jk;             /* location of p1 stone captured */
    int p2ik, p2jk;             /* location of p2 stone captured */
    int p1k, p2k;               /* no. of stones captured by p1 and p2 */
    int new=0;
    void showboard(int c);
    int main(int argc,char *argv[]){
     
    while ((c!=1)&&(c!=2)&&(c!=3)&&(c!=4)&&(c!=5)){
    	printf ("Taille du Goban:\n\t1) 5x5\n\t2) 7x7\n\t3) 9x9\n\t4) 13x13\n\t5) 19x19\n\nVotre choix:");
    	scanf("%d",&c);
    }
     
    if ((c==1))
    	{
    	/* init board */
    		for (i = 0; i < 5; i++)
    		for (j = 0; j < 5; j++)
    			p[i][j] = 0;
    	}
    if ((c==2))
    	{
    	/* init board */
    		for (i = 0; i < 7; i++)
    		for (j = 0; j < 7; j++)
    			p[i][j] = 0;
    	}
    if ((c==3))
    	{
    	/* init board */
    		for (i = 0; i < 9; i++)
    		for (j = 0; j < 9; j++)
    			p[i][j] = 0;
    	}
    if ((c==4))
    	{
    	/* init board */
    		for (i = 0; i < 13; i++)
    		for (j = 0; j < 13; j++)
    			p[i][j] = 0;
    	}
    if ((c==5))
    	{
    	/* init board */
    		for (i = 0; i < 19; i++)
    		for (j = 0; j < 19; j++)
    			p[i][j] = 0;
    	}
     
     
     
     if (!new)  /* new game */
         {
     
    /* choose color */
          printf("\nChoose side(b or w)? ");
          scanf("%c",ans);
          if (ans[0] == 'b')
            {
             p1move = 1;   /* P1 white */
             p2move = 2;   /* P2 black */
            }
          else
            {
             p1move = 2;   /* P1 black */
             p2move = 1;   /* P2 white */
           }
        }
     
    showboard(c);
     
    /* main loop
     * tant que pas capturer de pierres 
     * lit mouvement joueur1
     * enleve pierre
     * lit mouvement joueur2
     * enleve pierre
     * */
     
     
     
    return 0;
    }
    puis showboard.c
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    extern unsigned char p[19][19];
    extern int p1move, p2move;        /* p1 color, p2 color */
    extern int lib;                  /* current stone liberty */
    extern int p1ik, p1jk;             /* location of p1 stone captured */
    extern int p2ik, p2jk;             /* location of p2 stone captured */
    extern int p1k, p2k;               /* no. of stones captured by p1 and p2 */
    int ii=0;
    int i=0;
    int j=0;
    void showboard(int c){
     
    if (c==1){  /*goban 5x5*/
    	printf("   A B C D E\n");
    		for (i = 0; i < 5; i++){
    		ii = 5 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 5; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
    		printf("%2d",ii);
    		printf("\n");
     
    }
    	printf("   A B C D E\n");
    }
     
    if (c==2){  /*goban 7x7*/
    	printf("   A B C D E F G\n");
    		for (i = 0; i < 7; i++){
    		ii = 7 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 7; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
               	else printf(" X");
     
    		printf("%2d",ii);
    		printf("\n");
     
         }
    	printf("   A B C D E F G\n");
    }
     
    if (c==3){  /*goban 9x9*/ 
    	printf("   A B C D E F G H J\n");
    		for (i = 0; i < 9; i++){
    		ii = 9 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 9; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J\n");
    }
     
    if (c==4){  /*goban 13x13*/
    	printf("   A B C D E F G H J K L M N\n");
    		for (i = 0; i < 13; i++){
    		ii = 13 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 13; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J K L M N\n");
    }
     
    if (c==5){  /*goban19x19*/
    	printf("   A B C D E F G H J K L M N O P Q R S T\n");
    		for (i = 0; i < 19; i++){
    		ii = 19 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 19; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J K L M N O P Q R S T\n");
    }
    if (p2move == 1)
          printf("     Your color: White O\n");
       else
          if (p2move == 2)
    	 printf("     Your color: Black X\n");
          else
    	 printf("\n");
     if (p1move == 1)
    	    printf("     My color:   White O\n");
    	 else
    	    if (p1move == 2)
    	       printf("     My color:   Black X\n");
    	    else
    	       printf("\n");
    }
    mais une fois compilé je ne peux pas choisir entre black or white.
    J'y arrive quand j'utilise scanf(%d,&s) avec int mais pas avec char.
    Je ne sais pas de ou viens mon probleme.

    merci de votre aide

  2. #2
    Membre expérimenté Avatar de edgarjacobs
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    623
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 623
    Points : 1 554
    Points
    1 554
    Par défaut
    Hello,

    Je n'ai rien regardé d'autre, mais ans est un char[]. Jusque là, pas de souci. Mais si tu veux faire une scanf() d'un caractère (soit un char) dans ans, c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    char ans[2];       // ce que tu as écrit
    ....
    scanf("%c",&ans[0]);
     
    if(ans[0]=='b') {
        ....
    }
    On écrit "J'ai tort" ; "tord" est la conjugaison du verbre "tordre" à la 3ème personne de l'indicatif présent

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    Points : 45
    Points
    45
    Par défaut
    bonsoir edgarjacobs,

    J'ai essayé de rentrer ton code , mais cela n'a pas fonctionné.

    Merci quand meme.

  4. #4
    Expert éminent
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 565
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 565
    Points : 7 648
    Points
    7 648
    Par défaut
    Bonjour,

    Après une saisie, il reste le dernier retour chariot dans le buffer d'entrée (qui est auto filtré quand on lit un nombre ou un mot), pour lire un char il faut l'enlever. Ajoute avant ton scanf("%c",ans);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    {
        int c;
        do  c = getchar() while ( c != '\n'  &&  c != EOF );
    }

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    Points : 45
    Points
    45
    Par défaut
    lors de la compilation j'ai des warning:
    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
     
    cc -O   -c -o count.o count.c
    cc -O   -c -o countlib.o countlib.c
    cc -O   -c -o eval.o eval.c
    cc -O   -c -o exambord.o exambord.c
    cc -O   -c -o getij.o getij.c
    cc -O   -c -o getmove.o getmove.c
    getmove.c: In function ‘getmove’:
    getmove.c:22:16: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
                    scanf("%s", move);
                    ^
    cc -O   -c -o main.o main.c
    main.c: In function ‘main’:
    main.c:22:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d",&c);
      ^
    main.c:67:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&s);
     ^
    main.c:96:7: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
           scanf("%s", move);
           ^
    main.c:109:7: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
           scanf("%s", move);
           ^
    cc -O   -c -o showboard.o showboard.c
    cc -O   -c -o suicide.o suicide.c
    cc count.o countlib.o eval.o exambord.o getij.o getmove.o main.o showboard.o suicide.o -o gnugo
    /bin/rm -f *.o
    voici mon code:

    count.c
    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
     
    #include "aigo.h"
     
    extern unsigned char p[19][19];   /* go board */
    extern unsigned char ml[19][19];  /* working matrix for marking */
    extern int lib;                   /* current stone liberty */
     
    void count(int i,     /* row number 0 to 18 */
               int j,     /* column number 0 to 18 */
               int color) /* BLACK or WHITE */
    /* count liberty of color piece at location i, j
       and return value in lib */
    {
    /* set current piece as marked */
     ml[i][j] = EMPTY;
     
    /* check North neighbor */
     if (i != EMPTY)
       {
        if ((p[i - 1][j] == EMPTY) && ml[i - 1][j])
          {
           ++lib;
           ml[i - 1][j] = EMPTY;
         }
        else
           if ((p[i - 1][j] == color) && ml[i - 1][j])
    	  count(i - 1, j, color);
      }
    /* check South neighbor */
     if (i != 18)
       {
        if ((p[i + 1][j] == EMPTY) && ml[i + 1][j])
          {
           ++lib;
           ml[i + 1][j] = EMPTY;
         }
        else
           if ((p[i + 1][j] == color) && ml[i + 1][j])
    	  count(i + 1, j, color);
      }
    /* check West neighbor */
     if (j != EMPTY)
       {
        if ((p[i][j - 1] == EMPTY) && ml[i][j - 1])
          {
           ++lib;
           ml[i][j - 1] = EMPTY;
         }
        else
           if ((p[i][j - 1] == color) && ml[i][j - 1])
    	  count(i, j - 1, color);
      }
    /* check East neighbor */
     if (j != 18)
       {
        if ((p[i][j + 1] == EMPTY) && ml[i][j + 1])
          {
           ++lib;
           ml[i][j + 1] = EMPTY;
         }
        else
           if ((p[i][j + 1] == color) && ml[i][j + 1])
    	  count(i, j + 1, color);
      }
    }  /* end count */
    countlib.c
    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
     
    #include "aigo.h"
     
    extern unsigned char ml[19][19];  /* working matrix for marking */
     
    void countlib(int m,     /* row number 0 to 18 */
                  int n,     /* column number 0 to 18 */
                  int color) /* BLACK or WHITE */
    /* count liberty of color piece at m, n */
    {
     int i, j;
     
    /* set all piece as unmarked */
     for (i = 0; i < 19; i++)
       for (j = 0; j < 19; j++)
         ml[i][j] = 1;
     
    /* count liberty of current piece */
     count(m, n, color);
    }  /* end countlib */
    eval.c
    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
     
    #include "aigo.h"
     
    extern unsigned char p[19][19];   /* go board */
    extern unsigned char l[19][19];   /* liberty of current color */
    extern int lib;                   /* current stone liberty */
     
    void eval(int color)  /* BLACK or WHITE */
    /* evaluate liberty of color pieces */
     {
      int i, j;
     
    /* find liberty of each piece */
      for (i = 0; i < 19; i++)
        for (j = 0; j < 19; j++)
          if (p[i][j] == color)
    	{
    	 lib = 0;
    	 countlib(i, j, color);
    	 l[i][j] = lib;
          }
    }  /* end eval */
    exambord.c
    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
     
    #include "aigo.h"
     
    extern unsigned char p[19][19];   /* go board */
    extern unsigned char l[19][19];   /* liberty of current color */
    extern int p1move;                /* computer color */
    extern int p1ik, p1jk;  /* location of p1 stone captured */
    extern int p2ik, p2jk;  /* location of p2 stone captured */
    extern int p1k, p2k;    /* no. of stones captured by p1 and p2 */
     
    void examboard(int color) /* BLACK or WHITE */
    /* examine pieces */
    {
       int i, j, n;
     
    /* find liberty of each piece */
       eval(color);
     
    /* initialize piece captured */
       if (color == p1move)
         {
          p1ik = -1;
          p1jk = -1;
        }
       else
         {
          p2ik = -1;
          p2jk = -1;
        }
       n = 0; /* The number of captures this move for Ko purposes */
     
    /* remove all piece of zero liberty */
       for (i = 0; i < 19; i++)
         for (j = 0; j < 19; j++)
           if ((p[i][j] == color) && (l[i][j] == 0))
    	 {
    	  p[i][j] = EMPTY;
    /* record piece captured */
    	  if (color == p1move)
    	    {
    	     p1ik = i;
    	     p1jk = j;
    	     ++p1k;
    	   }
    	  else
    	    {
    	     p2ik = i;
    	     p2jk = j;
    	     ++p2k;
    	   }
    	  ++n;  /* increment number of captures on this move */
    	}
    /* reset to -1 if more than one stone captured since  no Ko possible */
       if (color == p1move && n > 1)
         {
           p1ik = -1;   
           p1jk = -1;
         }
       else if ( n > 1 )
         {
           p2ik = -1;
           p2jk = -1;
         }
    }  /* end examboard */
    getij.c
    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
     
    #include "aigo.h"
    unsigned char move[4];
    int getij(char move[],   /* move string */
              int *i,        /* move row number */
              int *j)        /* move column number */
    /* convert string input to i, j coordinate */
    {
     int k;
     
     if ((move[0] >= 'A') && (move[0] <= 'H'))
        *j = move[0] - 'A';
     else
        if ((move[0] >= 'J') && (move[0] <= 'T'))
           *j = move[0] - 'B';
        else
           if ((move[0] >= 'a') && (move[0] <= 'h'))
    	  *j = move[0] - 'a';
           else
    	  if ((move[0] >= 'j') && (move[0] <= 't'))
    	     *j = move[0] - 'b';
    	  else
    	     return 0;
     k = move[1] - '0';
     if (move[2]) k = k * 10 + move[2] - '0';
     *i = 19 - k;
     if ((*i >= 0) && (*i <= 18))
        return 1;
     else
        return 0;
    }  /* end getij */
    getmove.c
    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
     
    #include <stdio.h>
    #include <string.h>
    #include "aigo.h"
     
     
    extern unsigned char p[19][19];
    unsigned char move[3];
    extern int p1move, p2move;
    extern int p1k, p2k;        /* piece captured */
     
    void getmove(char move[],  /* move string */
                 int *i,       /* row number of next move */
                 int *j)       /* column number of next move */
    /* interpret response of human move to board position */
      {
    /* move[0] from A to T, move[1] move[2] from 1 to 19 */
    /* convert move to coordinate */
                if (!getij(move, i, j) || (p[*i][*j] != EMPTY) || suicide(*i, *j))
                  {
                   printf("illegal move !\n");
                   printf("your move? ");
                   scanf("%s", move);
                   getmove(move, i, j);
        }
    }  /* end getmove */
    aigo.h
    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
     
    /* definitions */
     
    #define EMPTY 0
    #define WHITE 1
    #define BLACK 2
     
    /* public functions */
     
    extern void count(int i,
                      int j,
                      int color);
     
    extern void countlib(int m,
                         int n,
                         int color);
     
    extern void eval(int color);
     
    extern void examboard(int color);
     
    extern int getij(char move[],
                     int *i,
                     int *j);
     
    extern void getmove(char move[],
                        int *i,
                        int *j);
     
     
    extern void showboard(int c);
     
     
    extern int suicide(int i,
                       int j);
    main.c
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include "aigo.h"
     
    int c=0;
    int i,j;
    unsigned char p[19][19];  /* go board */
    unsigned char l[19][19];  /* liberty of current color */
    unsigned char ma[19][19]; /* working matrix for marking */
    unsigned char ml[19][19]; /* working matrix for marking */
    int p1move, p2move;        /* p1 color, p2 color */
    int lib;                  /* current stone liberty */
    int p1ik, p1jk;             /* location of p1 stone captured */
    int p2ik, p2jk;             /* location of p2 stone captured */
    int p1k, p2k;          /* no. of stones captured by p1 and p2 */
    int s; /* side Black or White */
    unsigned char move[3];
    int main(int argc,char *argv[]){
     
    while ((c!=1)&&(c!=2)&&(c!=3)&&(c!=4)&&(c!=5)){
    	printf ("Taille du Goban:\n\t1) 5x5\n\t2) 7x7\n\t3) 9x9\n\t4) 13x13\n\t5) 19x19\n\nVotre choix:");
    	scanf("%d",&c);
    }
     
    if ((c==1))
    	{
    	/* init board */
    		for (i = 0; i < 5; i++)
    		for (j = 0; j < 5; j++)
    			p[i][j] = 0;
    	}
    if ((c==2))
    	{
    	/* init board */
    		for (i = 0; i < 7; i++)
    		for (j = 0; j < 7; j++)
    			p[i][j] = 0;
    	}
    if ((c==3))
    	{
    	/* init board */
    		for (i = 0; i < 9; i++)
    		for (j = 0; j < 9; j++)
    			p[i][j] = 0;
    	}
    if ((c==4))
    	{
    	/* init board */
    		for (i = 0; i < 13; i++)
    		for (j = 0; j < 13; j++)
    			p[i][j] = 0;
    	}
    if ((c==5))
    	{
    	/* init board */
    		for (i = 0; i < 19; i++)
    		for (j = 0; j < 19; j++)
    			p[i][j] = 0;
    	}
     
    showboard(c);
    int new=0;
     if (!new)  /* new game */
         {
    /* choose color */
          printf("Choisir couleur:\n\t1) Black\n\t2) White\n\nVotre choix:");
    scanf("%d",&s);
          if (s == 1)
            {
             p2move = 1;   /* player2 white */
             p1move = 2;   /* player 1 black */
     
           }
          else
            {
             p2move = 2;   /* player 2 black */
             p1move = 1;   /* player 1 white */
     
           }
        }
     
    showboard(c);
     
     
    /* main loop
     * tant que pas capturer de pierres 
     * lit mouvement joueur1
     * enleve pierre
     * lit mouvement joueur2
     * enleve pierre
     * */
     
    while ((p1k<0) || (p2k<0))
     {
    	printf("Black move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p1move;
    examboard(p2move);
    }
    else
    {
    p[i][j]= p2move;
    examboard(p1move);	
    	}
    		printf("White move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p2move;
    examboard(p1move);
    }
    else
    {
    p[i][j]= p1move;
    examboard(p2move);	
    	}
    	showboard(c);			
    }
    return 0;
    }
    Makefile
    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
     
    SRC = count.c \
          countlib.c \
          eval.c \
          exambord.c \
          getij.c \
          getmove.c \
          main.c \
          showboard.c \
          suicide.c
     
    PRG = aigo
     
    OBJ = $(SRC:.c=.o)
     
    CFLAGS = -O
     
    $(PRG) : $(OBJ)
    	$(CC) $(OBJ) -o $@
    	/bin/rm -f *.o
     
    $(OBJ) : aigo.h
    showboard.c
    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
     
    #include <stdio.h>
    #include "aigo.h"
    extern unsigned char p[19][19];
    extern int p1move, p2move;        /* p1 color, p2 color */
    extern int lib;                  /* current stone liberty */
    extern int p1ik, p1jk;             /* location of p1 stone captured */
    extern int p2ik, p2jk;             /* location of p2 stone captured */
    extern int p1k, p2k;               /* no. of stones captured by p1 and p2 */
    int ii=0;
    int i=0;
    int j=0;
    void showboard(int c){
     
    if (c==1){  /*goban 5x5*/
    	printf("   A B C D E\n");
    		for (i = 0; i < 5; i++){
    		ii = 5 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 5; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
    		printf("%2d",ii);
    		printf("\n");
     
    }
    	printf("   A B C D E\n");
    }
     
    if (c==2){  /*goban 7x7*/
    	printf("   A B C D E F G\n");
    		for (i = 0; i < 7; i++){
    		ii = 7 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 7; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
               	else printf(" X");
     
    		printf("%2d",ii);
    		printf("\n");
     
         }
    	printf("   A B C D E F G\n");
    }
     
    if (c==3){  /*goban 9x9*/ 
    	printf("   A B C D E F G H J\n");
    		for (i = 0; i < 9; i++){
    		ii = 9 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 9; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J\n");
    }
     
    if (c==4){  /*goban 13x13*/
    	printf("   A B C D E F G H J K L M N\n");
    		for (i = 0; i < 13; i++){
    		ii = 13 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 13; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J K L M N\n");
    }
     
    if (c==5){  /*goban19x19*/
    	printf("   A B C D E F G H J K L M N O P Q R S T\n");
    		for (i = 0; i < 19; i++){
    		ii = 19 - i;
    		printf("%2d",ii);
     
    		for (j = 0; j < 19; j++)
    			if (p[i][j] == 0)
    			printf(" -");
    			else if (p[i][j] == 1)
                    printf(" O");
                	else printf(" X");
     
          		printf("%2d",ii);
          		printf("\n");
     
         }
    	printf("   A B C D E F G H J K L M N O P Q R S T\n");
    }
    if (p1move == 1)
          printf("Player 1 color: White O\n");
       else
          if (p1move == 2)
    	 printf("Player 1 color: Black X\n");
          else
    	 printf("\n");
     if (p2move == 1)
    	    printf("Player 2 color: White O\n");
    	 else
    	    if (p2move == 2)
    	       printf("Player 2 color: Black X\n");
    	    else
    	       printf("\n");
    }
    suicide.c
    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
     
    #include "aigo.h"
     
    extern unsigned char p[19][19];  /* go board */
    extern unsigned char l[19][19];  /* liberty of current color */
    extern int p1move, p2move;        /* p1 color, p2 color */
    extern int lib;                  /* current stone liberty */
    extern int p2ik, p2jk;             /* location of p2 stone captured */
     
    int suicide(int i,
                int j)
    /* check for suicide move of opponent at p[i][j] */
    {
     int m, n, k;
     
    /* check liberty of new move */
     lib = 0;
     countlib(i, j, p2move);
     if (lib == 0)
    /* new move is suicide then check if kill p1 pieces and Ko possibility */
       {
    /* assume alive */
        p[i][j] = p2move;
     
    /* check p1 pieces */
        eval(p1move);
        k = 0;
     
        for (m = 0; m < 19; m++)
          for (n = 0; n < 19; n++)
    /* count pieces will be killed */
    	if ((p[m][n] == p1move) && !l[m][n]) ++k;
     
        if ((k == 0) || (k == 1 && ((i == p2ik) && (j == p2jk))))
    /* either no effect on p1 pieces or an illegal Ko take back */
          {
           p[i][j] = EMPTY;   /* restore to open */
           return 1;
          }
        else
    /* good move */
          return 0;
       }
     else
    /* valid move */
       return 0;
    }  /* end suicide */
    je ne sais pas si j'ai fais beaucoup d'erreurs dans mon code.
    Merci pour vos commentaires.

  6. #6
    Responsable Systèmes


    Homme Profil pro
    Gestion de parcs informatique
    Inscrit en
    Août 2011
    Messages
    17 446
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Gestion de parcs informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Août 2011
    Messages : 17 446
    Points : 43 090
    Points
    43 090
    Par défaut
    C'est la même erreur, ou du moins le même warning.

    La fonction scanf retourne le nombre d'éléments entrés et traités par la fonction. Tu as un avertissement car tu ne récupères pas cette valeur.
    Ma page sur developpez.com : http://chrtophe.developpez.com/ (avec mes articles)
    Mon article sur le P2V, mon article sur le cloud
    Consultez nos FAQ : Windows, Linux, Virtualisation

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    Points : 45
    Points
    45
    Par défaut
    Bonjour,

    pour les 2 warning :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    main.c: In function ‘main’:
    main.c:22:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d",&c);
      ^
    main.c:67:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&s);
    j'arrive a recuperer les valeurs car je peux choisir la taille du goban et choisir Black or white

    par contre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    getmove.c: In function ‘getmove’:
    getmove.c:22:16: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
                    scanf("%s", move);
    main.c:96:7: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
           scanf("%s", move);
           ^
    main.c:109:7: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
           scanf("%s", move);
    je n'arrive pas à recuperer les valeurs move. Et je ne sais pas comment faire.

    Merci de votre aide

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    Points : 45
    Points
    45
    Par défaut
    j'ai modifié dans main.c la boucle principale:

    pour voir le nombres de pierres j'ai mis un printf avec %d et p1k et p2k pour les pierres noires et blanches.

    c'est comme ci p1k et p2k n'etaient pas initialisés

    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
     
    /* main loop
     * tant que pas capturer de pierres 
     * lit mouvement joueur1
     * enleve pierre
     * lit mouvement joueur2
     * enleve pierre
     * */
    int p1k = 0;
    int p2k = 0;
    while ((p1k<1) || (p2k<1))
     {
    	printf("pierre noire: %d\n pierre blanche: %d \n", &p1k,&p2k);
    	printf("Black move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p1move;
    examboard(p2move);
    }
    else
    {
    p[i][j]= p2move;
    examboard(p1move);	
    	}
    showboard(c);
    		printf("White move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p2move;
    examboard(p1move);
    }
    else
    {
    p[i][j]= p1move;
    examboard(p2move);	
    	}
    	showboard(c);
    merci de votre aide
    ps: par contre je me suis accès sur plus la taille du goban 19x19 donc si vous voulez tester mon code. Je vous conseille de choisir comme taille goban 19x19 correspondant au choix 5.

  9. #9
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 689
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 689
    Points : 30 983
    Points
    30 983
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par ludovic787 Voir le message
    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
     
    /* main loop
     * tant que pas capturer de pierres 
     * lit mouvement joueur1
     * enleve pierre
     * lit mouvement joueur2
     * enleve pierre
     * */
    int p1k = 0;
    int p2k = 0;
    while ((p1k<1) || (p2k<1))
     {
    	printf("pierre noire: %d\n pierre blanche: %d \n", &p1k,&p2k);
    	printf("Black move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p1move;
    examboard(p2move);
    }
    else
    {
    p[i][j]= p2move;
    examboard(p1move);	
    	}
    showboard(c);
    		printf("White move? ");
          scanf("%s", move);
          getmove(move, &i, &j);   /* read human move */
    if (s == 1)
        {
    p[i][j]= p2move;
    examboard(p1move);
    }
    else
    {
    p[i][j]= p1move;
    examboard(p2move);	
    	}
    	showboard(c);
    Bonjour

    Déjà un code ça s'indente correctement. Comme ça, un programmeur C habitué peut d'un regard rapide évaluer ce qui est dans la boucle, ce qui n'y est pas, bref se redessiner l'algo dans sa tête. S'il faut lire 15 fois le code pour comprendre pourquoi tu fais deux fois getmove(move, &i, &j); /* read human move */ suivi du même test if (s == 1) parce que t'es infoutu d'écrire proprement ben désolé, j'ai autre chose à faire. Je sais pas moi, quand tu lis un livre, t'apprécies que les lignes soient bien calées proprement et alignées autant à gauche qu'à droite non ? Et inversement tu lirais peut-être moins facilement un livre où les lignes sont désalignées. Ben un programme, c'est pareil. Franchement, t'arrives à te relire toi-même ???

    Citation Envoyé par ludovic787 Voir le message
    printf("pierre noire: %d\n pierre blanche: %d \n", &p1k,&p2k);.
    c'est comme si p1k et p2k n'etaient pas initialisés
    Mouais. Je pense que là, il y a un souci. Accessoirement je n'ai vu nulle part p1 et p2 modifiées dans ta boucle...

    Citation Envoyé par ludovic787 Voir le message
    ps: par contre je me suis accès sur plus la taille du goban 19x19 donc si vous voulez tester mon code. Je vous conseille de choisir comme taille goban 19x19 correspondant au choix 5.
    Mouais. Même ça je ne le comprends pas. Quand on imagine son algo, on l'imagine de façon un peu universelle (style "je pars de 0 et je vais jusqu'à l'autre bord qui est en paramètre"). Si par exemple j'imagine la somme d'un tableau, je partirai sur "je commence à 0 et je continue jusqu'à atteindre le nombre d'éléments". Ainsi, mon algo fonctionnera aussi bien sur un tableau de 10 que de 100. Toi, pour ton jeu de go, ça aurait dû être la même chose...
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  10. #10
    Expert confirmé
    Inscrit en
    Mars 2005
    Messages
    1 431
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 1 431
    Points : 4 182
    Points
    4 182
    Par défaut
    Le compilateur est capable de t'indiquer certaines coquilles comme cet appel erroné à printf.

    Configure ta chaîne de compilation comme ceci :

    • commence par désactiver les optimisations (on les utilise pour les builds destinés à être déployés) : retire -O ;
    • puis spécifie une norme : ajoute -std=c11 -pedantic ;
    • et active les avertissements : ajoute -Wall -Wextra ;
    • voire la génération d'informations supplémentaires si tu veux pouvoir débugger : ajoute -ggdb (ou -g).
    • C'est plus avancé mais au besoin active également un ou plusieurs sanitizers : -fsanitize=address, -fsanitize=undefined...

Discussions similaires

  1. [utf8] Problème lors de la compilation
    Par ChipsterJulien dans le forum Editeurs / Outils
    Réponses: 1
    Dernier message: 10/03/2006, 17h36
  2. [Free Pascal] Problème lors de la compilation
    Par llaurentt dans le forum Free Pascal
    Réponses: 2
    Dernier message: 31/01/2006, 09h40
  3. Probleme lors de la compilation...
    Par Draleg dans le forum C
    Réponses: 15
    Dernier message: 08/12/2005, 17h14
  4. [Debutant] probleme lors de la compilation
    Par boobi dans le forum Débuter
    Réponses: 5
    Dernier message: 26/08/2005, 15h57
  5. [MYSQL] Probleme lors de la compilation
    Par Nasky dans le forum Autres éditeurs
    Réponses: 10
    Dernier message: 24/02/2004, 17h04

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