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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    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 Expert Avatar de edgarjacobs
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    800
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 65
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 800
    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') {
        ....
    }

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

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

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

    Merci quand meme.

  4. #4
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 600
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    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 600
    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 confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 70
    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
    18 374
    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 : 18 374
    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

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, 18h36
  2. [Free Pascal] Problème lors de la compilation
    Par llaurentt dans le forum Free Pascal
    Réponses: 2
    Dernier message: 31/01/2006, 10h40
  3. Probleme lors de la compilation...
    Par Draleg dans le forum C
    Réponses: 15
    Dernier message: 08/12/2005, 18h14
  4. [Debutant] probleme lors de la compilation
    Par boobi dans le forum Débuter
    Réponses: 5
    Dernier message: 26/08/2005, 16h57
  5. [MYSQL] Probleme lors de la compilation
    Par Nasky dans le forum Autres éditeurs
    Réponses: 10
    Dernier message: 24/02/2004, 18h04

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