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 :

Erreur de segmentation


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 252
    Par défaut Erreur de segmentation
    Bonjour à tous.
    J'ai une erreur de segmentation dans mon fichier que je fourni en piece jointe.
    J'ai creusé un petit peu, car je ne savais pas trop comment faire...
    Comme je suis sous linnux, j'utilise gdb.
    Il y a une erreur sur free(), avec un renvoit à une bibliothéque.
    J'ai également vérifier quelles fonctions été appelées.
    free() est appellé par demarre qui est appellé par la fonction main.
    L'erreur exacte est
    #0 0xb7e997bc in free () from /lib/tls/i686/cmov/libc.so.6
    #1 0x08049b26 in demarre () at othello.c:142
    #2 0x080496b0 in main () at othello.c:19
    Est ce que quelqu'un pourrait m'aider s'il vous plait ?
    Merci d'avance

  2. #2
    Expert confirmé
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Par défaut
    Comment te répondre ?
    - On ne connait pas les types particuliers de ton problème (JOUEUR ?)
    - On ne connait pas les variables J2, J4 , othelier, chemin,....ni la déclaration de leur type
    - On voit des free, mais on ne sait pas où sont les malloc correspondant.

  3. #3
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 252
    Par défaut
    Il s'agit du jeu othello, J2 et J4 sont des joueurs, othello est une fonction qui attribution une valeur à des cases (X, O ou ., . represente le vide pour une case.
    Je fourni en piece jointe le fichier sauvegarde ou toutes les fonctions pour sauvegarder sont présentent
    Pour info, toutes les primitives sont définis dans des hearder à part, le projet compile sans souci, mais quand je sauvegarde (à la fin d'un jeu) j'ai 2 chances sur trois pour me faire insulter par mon ordinateur

  4. #4
    Membre Expert Avatar de nicolas.sitbon
    Profil pro
    Inscrit en
    Août 2007
    Messages
    2 015
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 2 015
    Par défaut
    poste tout le code sinon comment veux tu que l'on compile!!

  5. #5
    Membre très actif
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 252
    Par défaut
    Voici l'intégralité de la source
    Merci pour votre aide
    Pour compiler, vous fait un make, le makefile contenant l'option -g, pour débuguer, j'ai utilisé gdb

    Edit: erreur lors de l'envoi du zip

  6. #6
    Membre Expert Avatar de nicolas.sitbon
    Profil pro
    Inscrit en
    Août 2007
    Messages
    2 015
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 2 015
    Par défaut
    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
    In file included from evaluation.c:8:
    sauvegarde.h:1: attention : function declaration isn"t a prototype
    sauvegarde.h:10: attention : function declaration isn"t a prototype
    sauvegarde.h:11: attention : function declaration isn"t a prototype
    In file included from evaluation.c:12:
    othello.h:1: attention : function declaration isn"t a prototype
    othello.h:2: attention : function declaration isn"t a prototype
    othello.h:3: attention : function declaration isn"t a prototype
    othello.h:4: attention : function declaration isn"t a prototype
    othello.h:5: attention : function declaration isn"t a prototype
    othello.h:6: attention : function declaration isn"t a prototype
    In file included from alpha.c:8:
    sauvegarde.h:1: attention : function declaration isn"t a prototype
    sauvegarde.h:10: attention : function declaration isn"t a prototype
    sauvegarde.h:11: attention : function declaration isn"t a prototype
    In file included from alpha.c:12:
    othello.h:1: attention : function declaration isn"t a prototype
    othello.h:2: attention : function declaration isn"t a prototype
    othello.h:3: attention : function declaration isn"t a prototype
    othello.h:4: attention : function declaration isn"t a prototype
    othello.h:5: attention : function declaration isn"t a prototype
    othello.h:6: attention : function declaration isn"t a prototype
    alpha.c:20: attention : no previous prototype for «max"
    alpha.c:28: attention : no previous prototype for «min"
    alpha.c: In function «CompteCasesVides":
    alpha.c:39: attention : unused parameter «Grille"
    In file included from regles.c:4:
    sauvegarde.h:1: attention : function declaration isn"t a prototype
    sauvegarde.h:10: attention : function declaration isn"t a prototype
    sauvegarde.h:11: attention : function declaration isn"t a prototype
    In file included from regles.c:10:
    othello.h:1: attention : function declaration isn"t a prototype
    othello.h:2: attention : function declaration isn"t a prototype
    othello.h:3: attention : function declaration isn"t a prototype
    othello.h:4: attention : function declaration isn"t a prototype
    othello.h:5: attention : function declaration isn"t a prototype
    othello.h:6: attention : function declaration isn"t a prototype
    regles.c: In function «faitpriseDansDirection":
    regles.c:15: attention : «contenu" may be used uninitialized in this function
    In file included from othello.c:8:
    sauvegarde.h:1: attention : function declaration isn"t a prototype
    sauvegarde.h:10: attention : function declaration isn"t a prototype
    sauvegarde.h:11: attention : function declaration isn"t a prototype
    In file included from othello.c:10:
    othello.h:1: attention : function declaration isn"t a prototype
    othello.h:2: attention : function declaration isn"t a prototype
    othello.h:3: attention : function declaration isn"t a prototype
    othello.h:4: attention : function declaration isn"t a prototype
    othello.h:5: attention : function declaration isn"t a prototype
    othello.h:6: attention : function declaration isn"t a prototype
    othello.c:14: attention : function declaration isn"t a prototype
    othello.c:30: attention : function declaration isn"t a prototype
    othello.c:44: attention : function declaration isn"t a prototype
    othello.c:57: attention : function declaration isn"t a prototype
    othello.c:71: attention : function declaration isn"t a prototype
    othello.c:151: attention : function declaration isn"t a prototype
    othello.c: In function «demarre":
    othello.c:73: attention : «score" may be used uninitialized in this function
    In file included from representation.c:4:
    sauvegarde.h:1: attention : function declaration isn"t a prototype
    sauvegarde.h:10: attention : function declaration isn"t a prototype
    sauvegarde.h:11: attention : function declaration isn"t a prototype
    In file included from representation.c:10:
    othello.h:1: attention : function declaration isn"t a prototype
    othello.h:2: attention : function declaration isn"t a prototype
    othello.h:3: attention : function declaration isn"t a prototype
    othello.h:4: attention : function declaration isn"t a prototype
    othello.h:5: attention : function declaration isn"t a prototype
    othello.h:6: attention : function declaration isn"t a prototype
    representation.c: In function «initialiseGrilleDepart":
    representation.c:27: erreur: expected «)" before «othelier"
    representation.c:237: erreur: expected declaration or statement at end of input
    representation.c:237: erreur: expected declaration or statement at end of input
    representation.c:237: erreur: expected declaration or statement at end of input
    si tu indentais correctement ton code tu aurais remarqué :
    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
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    #include<stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "sauvegarde.h"
    #include "evaluation.h"
    #include "alpha.h"
    #include "regles.h"
    #include "representation.h"
    #include "optimisation.h"
    #include "othello.h"
     
    int NBCOUPS_JOUES;
    char CAMP_QUI_A_JOUE;           /*met en evidence les cases jouables */
    void initialiseGrilleDepart (int taille)
    {
       int i, j;
       taille = 8;
       Dimmax = taille;
     
       othelier = (char *) malloc ((Dimmax * Dimmax * sizeof (char)));
     
       for (i = 0; i < taille; i++)
       {
          for (j = 0; j < taille; j++)
          {
             if ((i == 3) && (j == 3)
                 othelier[Dimmax * i + j] = 'O';
                 else
                 if ((i == 4) && (j == 4)
                     othelier[Dimmax * i + j] = 'O';
     
                     else
                     if ((i == 3) && (j == 4)
                         othelier[Dimmax * i + j] = 'X';
     
                         else
                         if ((i == 4) && (j == 3)
                             othelier[Dimmax * i + j] = 'X';
                             else
                             othelier[Dimmax * i + j] = '.';
     
                             }
                             }
                             }
     
                             void afficheothellier (char *Grille)
                             {
     
                             int Ligne, k;
                             char Colone;
                             char Camp = adverse (CAMP_QUI_A_JOUE);
                 printf ("\n\t\tOTHELIER  %d X %d \n\n\n\t   ", Dimmax, Dimmax);
                             for (Colone = 'a'; Colone < Dimmax + 'a'; Colone++)
                             printf (" %c  ", Colone);
                             printf ("\n\t  +");
                             for (Ligne = 1; Ligne <= Dimmax; Ligne++)
                             {
                             for (k = 1; k <= Dimmax; k++)
                             printf ("---+");
                             printf ("\n\t%d ", Ligne);
                             for (Colone = 'a'; Colone < Dimmax + 'a'; Colone++)
                             {
                             if ((coupValide (Grille, Camp, Ligne, Colone)) == 1)
                             printf ("| - ");  /*mettre la case en evidance */
                             else
                        if ((Grille[Dimmax * (Ligne - 1) + Colone - 97]) == '.')
                             printf ("|   ");  /*afficher le vide */
                             else
                   printf ("| %c ", Grille[Dimmax * (Ligne - 1) + Colone - 97]);
                             }
                             printf ("| %d\n\t  +", Ligne);
                             }
                             for (k = 1; k <= Dimmax; k++)
                             printf ("---+");
                             printf ("\n\t   ");
                             for (Colone = 'a'; Colone < Dimmax + 'a'; Colone++)
                             printf (" %c  ", Colone);
                             printf ("\n");
     
                             }
     
                   void newposition (int *ptrNumligne, char *ptrNomcol, int dir)
     
                             {
       /* droite */
                             if (dir == 1)
                             (*ptrNomcol)++;
                             else
       /* Diagonale bas - droite */
                             if (dir == 2)
                             {
                             (*ptrNumligne)++;
                             (*ptrNomcol)++;
                             }
                             else
       /*bas */
                             if (dir == 3)
                             (*ptrNumligne)++;
                             else
       /* Diagonale bas - gauche */
                             if (dir == 4)
                             {
                             (*ptrNumligne)++;
                             (*ptrNomcol)--;
                             }
     
                             else
       /*  gauche */
                             if (dir == 5)
                             {
                             (*ptrNomcol)--;
                             }
     
                             else
       /* Diagonale haut - gauche */
                             if (dir == 6)
                             {
                             (*ptrNumligne)--;
                             (*ptrNomcol)--;
                             }
     
                             else
       /* Haut */
                             if (dir == 7)
                             {
                             (*ptrNumligne)--;
                             }
     
                             else
       /* Diagonale Haut  - droite */
                             if (dir == 8)
                             {
                             (*ptrNumligne)--;
                             (*ptrNomcol)++;
                             }
                             }
     
                             int retournePionsDansDirection (int Dir, char **Grille, int Numligne, char Nomcol, char camp)
     
                             {
                             int compteur = 0;
                             char contenu;
     
                             while ((Numligne >= 1) && (Numligne <= Dimmax) && (Nomcol >= 'a') && ((Nomcol - 'a') < Dimmax))
                             {
                             newposition (&Numligne, &Nomcol, Dir);
                       contenu = donnecontenudecase (*Grille, Numligne, Nomcol);
     
                             if ((contenu != camp) && (contenu != '.'))
                             {
                   (*Grille)[(Dimmax * (Numligne - 1)) + (Nomcol - 'a')] = camp;
                             compteur++;
                             }
                             else
                             break;
                             }
                             return compteur;
     
                             }
     
         int retournePions (char **Grille, int Numligne, char Nomcol, char camp)
     
                             {
                             int compteur = 0;
                             int dir;
                          if (coupValide (*Grille, camp, Numligne, Nomcol) == 1)
                             {
                             for (dir = 1; dir <= 8; dir++)
                             {
                             if (faitpriseDansDirection (dir, camp, *Grille, Numligne, Nomcol) == 1)
                             compteur += retournePionsDansDirection (dir, Grille, Numligne, Nomcol, camp);
                             }
                             }
                             return compteur;
                             }
     
             void JoueLeCoup (char **Grille, int Numlig, char Nomcol, char Camp)
                             {
                             retournePions (Grille, Numlig, Nomcol, Camp);
               (*Grille)[(Dimmax * (Numlig - 1)) + (int) (Nomcol - 'a')] = Camp;
                             }
     
                         void SaisiUnCoup (char Camp, int *Numlig, char *Nomcol)
                             {
                             do
                             {
                             printf ("ENTREZ LA CASE  A JOUER:\t");
                             scanf ("%c %d", Nomcol, Numlig);
                             getchar ();
                             if (*Nomcol != 'u')
                             {
                         if (coupValide (othelier, Camp, *Numlig, *Nomcol) == 0)
                             {
                     printf ("\n SAISIE  INVALIDE (%c,%d)\n", *Nomcol, *Numlig);
                             afficheothellier (othelier);
                             }
                             }
                             else
                             {
                             if (NBCOUPS_JOUES >= 6)
                             {
                           printf ("\n ANNULLATION DU DERNIER COUP EN COURS\n");
                             break;
                             }
                             else
                             {
                          printf ("\n IMPOSSIBLE DE REVENIR PLUS EN ARRIERE\n");
                             afficheothellier (othelier);
                             }
                             }
                             }
                     while (coupValide (othelier, Camp, *Numlig, *Nomcol) == 0);
                             }
     
                          void recopieGrille (char *Grilledeteste, char *Grille)
                             {
                             int i;
                             char j;
                             for (i = 1; i <= Dimmax; i++)
                             {
                             for (j = 'a'; j < Dimmax + 'a'; j++)
                             {
                             Grilledeteste[(Dimmax * (i - 1)) + (int) (j - 'a')] = donnecontenudecase (Grille, i, j);
                             }
                             }
                             }
     
                             void affichecoup (char colonne, int ligne)
                             {
                        printf ("\n\t  coup joue:  (%c,%d) \n", colonne, ligne);
                             }

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

Discussions similaires

  1. Erreurs de segmentation !
    Par anti-conformiste dans le forum Applications et environnements graphiques
    Réponses: 16
    Dernier message: 18/10/2005, 11h11
  2. Erreur de segmentation
    Par Trunks dans le forum C
    Réponses: 3
    Dernier message: 06/10/2005, 18h28
  3. Erreur de segmentation (Inconnue)
    Par Dark-Meteor dans le forum C
    Réponses: 5
    Dernier message: 08/09/2005, 13h42
  4. [Dev-C++] Erreur de segmentation...
    Par sas dans le forum Dev-C++
    Réponses: 11
    Dernier message: 26/03/2005, 14h25
  5. erreur de segmentation
    Par transistor49 dans le forum C++
    Réponses: 10
    Dernier message: 15/03/2005, 11h18

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