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 :

fonction qui plante mon programme


Sujet :

C

  1. #1
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut fonction qui plante mon programme
    Bonsoir à tous, jai un probleme avec une focntion qui plante mon programme
    cette fonction verifie si un mot donné est present dans une table de hachage.
    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
    unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){ 
     
    	Liste *p; 
    	unsigned int cle; 
     
    	cle = HashCode(mot); 
    	for(p=TableHash[cle];p!=NULL;p=p->suivant) 
    		if(strcmp(p->m->mot,mot)==0) 
    			return 1; 
    		return 0; 
    } 
     
     
     
    unsigned int HashCode (char *ligne)
    {
        int i;
        int  Code=0;
    	for (i=0;i< strlen(ligne);i++)
    	Code=ligne[i]+31*Code;
    	return Code%101;
    }
    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h> 
     
    #include "table_hash.h" 
    #define TAILLEHASH 307 
    #define NBRSEQ 10 
    #define SEUIL 3 
    #define SEUIL 3 
     
    int main() 
    { 
        FILE *F=NULL; 
    	char mot[100]; 
    	int i,j; 
    	unsigned int cle,pt; 
    	int nl=1, pos=1; 
    	//nl=pos=1; 
    	int f; 
    	char c; 
    	//int seuil; 
    	//Liste **L; 
    	Liste *seq2=NULL; 
    	Liste **seq; 
     
    	Liste **TableHash; 
    	TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *)); 
    	for(i=0;i<TAILLEHASH;++i) 
    		TableHash[i] = NULL; 
    		pt=HashCode("."); 
    	//printf("%d",pt); 
     
    	printf("debut du programme \n----------------------------------\n");   
    	F=fopen("C:\\essai.txt","r"); 
    	printf("Ouverture du Fichier \n----------------------------------\n");   
    	while(fscanf(F,"%s",mot)==1){ 
    		cle = HashCode(mot); 
    		printf("%i", cle);
    		printf("-");
    	if ((cle!=pt ) && (!ChercherMotDansTableHash(TableHash,mot)) )
    	printf("fghf");
              // TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
    		/*	if(fgetc(F)==EOF)
    			break;*/
    	} 
    	fclose(F); 
     
    scanf("%s", c);
    }
    merci de vouloir m'aider
    Le jour est le père du labeur et la nuit est la mère des pensées.

  2. #2
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    Bonsoir à tous, jai un probleme avec une focntion qui plante mon programme
    Ce code est incomplet
    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
     
     
    -------------- Build: Debug in hello ---------------
     
    Compiling: main.c
    C:\dev\hello\main.c:1: error: syntax error before '*' token
    C:\dev\hello\main.c:1: warning: function declaration isn't a prototype
    C:\dev\hello\main.c: In function `ChercherMotDansTableHash':
    C:\dev\hello\main.c:3: error: `Liste' undeclared (first use in this function)
    C:\dev\hello\main.c:3: error: (Each undeclared identifier is reported only once
    C:\dev\hello\main.c:3: error: for each function it appears in.)
    C:\dev\hello\main.c:3: error: `p' undeclared (first use in this function)
    C:\dev\hello\main.c:6: warning: implicit declaration of function `HashCode'
    C:\dev\hello\main.c:6: error: `mot' undeclared (first use in this function)
    C:\dev\hello\main.c:7: error: `TableHash' undeclared (first use in this function)
    C:\dev\hello\main.c:7: error: `NULL' undeclared (first use in this function)
    C:\dev\hello\main.c:8: warning: implicit declaration of function `strcmp'
    C:\dev\hello\main.c: At top level:
    C:\dev\hello\main.c:16: error: conflicting types for 'HashCode'
    C:\dev\hello\main.c:6: error: previous implicit declaration of 'HashCode' was here
    C:\dev\hello\main.c: In function `HashCode':
    C:\dev\hello\main.c:19: warning: implicit declaration of function `strlen'
    C:\dev\hello\main.c:19: warning: comparison between signed and unsigned
    C:\dev\hello\main.c:27:24: table_hash.h: No such file or directory
    C:\dev\hello\main.c: At top level:
    C:\dev\hello\main.c:34: warning: function declaration isn't a prototype
    C:\dev\hello\main.c: In function `main':
    C:\dev\hello\main.c:48: error: `Liste' undeclared (first use in this function)
    C:\dev\hello\main.c:48: error: `seq2' undeclared (first use in this function)
    C:\dev\hello\main.c:49: error: `seq' undeclared (first use in this function)
    C:\dev\hello\main.c:51: error: `TableHash' undeclared (first use in this function)
    C:\dev\hello\main.c:52: error: syntax error before ')' token
    C:\dev\hello\main.c:55: warning: passing arg 1 of `HashCode' discards qualifiers from pointer target type
    C:\dev\hello\main.c:76: warning: format argument is not a pointer (arg 2)
    C:\dev\hello\main.c:37: warning: unused variable `j'
    C:\dev\hello\main.c:39: warning: unused variable `nl'
    C:\dev\hello\main.c:39: warning: unused variable `pos'
    C:\dev\hello\main.c:42: warning: unused variable `f'
    Process terminated with status 1 (0 minutes, 0 seconds)
    16 errors, 12 warnings
    et il faudrait un exemple de fichier...
    Pas de Wi-Fi à la maison : CPL

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

    Informations forums :
    Inscription : Août 2007
    Messages : 2 015
    Points : 2 280
    Points
    2 280
    Par défaut
    Citation Envoyé par cyrine Voir le message
    Corrige ça!! j'ai pas regardé le reste, ça m'a simplement sauter au yeux.
    "The quieter you become, the more you are able to hear"
    "Plus vous êtes silencieux, plus vous êtes capable d'entendre"

  4. #4
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    ok
    voila ca c'est le 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
    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h> 
     
    #include "table_hash.h" 
    #define TAILLEHASH 307 
    #define NBRSEQ 10 
    #define SEUIL 3 
    #define SEUIL 3 
     
    int main() 
    { 
        FILE *F=NULL; 
    	char mot[100]; 
    	int i,j; 
    	unsigned int cle,pt; 
    	int nl=1, pos=1; 
    	//nl=pos=1; 
    	int f; 
    	char c; 
    	//int seuil; 
    	//Liste **L; 
    	Liste *seq2=NULL; 
    	Liste **seq; 
     
    	Liste **TableHash; 
    	TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *)); 
    	for(i=0;i<TAILLEHASH;++i) 
    		TableHash[i] = NULL; 
    		pt=HashCode("."); 
    	//printf("%d",pt); 
     
    	printf("debut du programme \n----------------------------------\n");   
    	F=fopen("C:\\essai.txt","r"); 
    	printf("Ouverture du Fichier \n----------------------------------\n");   
    	while(fscanf(F,"%s",mot)==1){ 
    		cle = HashCode(mot); 
    		printf("%i", cle);
    		printf("-");
    	if ((cle!=pt ) && (!ChercherMotDansTableHash(TableHash,mot)) )
    	printf("fghf");
              // TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
    		/*	if(fgetc(F)==EOF)
    			break;*/
    	} 
    	fclose(F); 
     
    scanf("%s", c);
    }
     
    unsigned int HashCode (char *ligne)
    {
        int i;
        int  Code=0;
    	for (i=0;i< strlen(ligne);i++)
    	Code=ligne[i]+31*Code;
    	return Code%101;
    }
    unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){ 
     
    	Liste *p; 
    	unsigned int cle; 
     
    	cle = HashCode(mot); 
    	for(p=TableHash[cle];p!=NULL;p=p->suivant) 
    		if(strcmp(p->m->mot,mot)==0) 
    			return 1; 
    		return 0; 
    } 
    mots *InsertionEnTeteMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = m; 
     
    	return nouveau; 
    }
    Liste *InsertionEnTete(Liste *L,char *mot){ 
    	Liste *nouveau; 
    	nouveau = (Liste *) malloc (sizeof(Liste)); 
    	nouveau->freq=0; 
    	nouveau->m=NULL; 
    	nouveau->m=InsertionEnTeteMot(nouveau->m,mot); 
    	nouveau->m = InsertionEnQueueMot(nouveau->m,mot);
    	nouveau->suivant = L; 
    	nouveau->c = NULL; 
    	return nouveau; 
    } 
    mots *InsertionEnQueueMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = NULL; 
     
    	if(m==NULL)
    		return nouveau; 
    	else
    	{
    		m->suivant = nouveau;
    		return m;
    	}
    }

    cela est le header "table_hash.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
    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
    #ifndef TABLE_HASH 
    #define TABLE_HASH 
     
    typedef struct c{ 
    	int pos; 
    	int nl; 
    	struct c *suivant; 
    }Coordonnees; 
     
    typedef struct L{ 
    	char  mot[50]; 
    	Coordonnees *c; 
    	struct L *suivant; 
    }Liste1; 
     
    typedef struct m{ 
    	char mot[50]; 
    	struct m *suivant; 
    }mots; 
     
    typedef struct L2{ 
        int freq; 
    	mots *m; 
    	Coordonnees *c; 
    	struct L2 *suivant; 
    }Liste; 
     
    int nb_lignes (FILE *fp) 
    { 
      int n=0; 
      char c; 
     
      while ((c = fgetc(fp)) != EOF) 
      { 
        if (c == '\n') 
        { 
          n++; 
        } 
      } 
      return n; 
    } 
     
     
     
    Liste *InsertionEnTete(Liste *L,char *mot); 
    Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos); 
    mots *InsertionEnTeteMot(mots *m,char mot[50]); 
    void AfficherListe(Liste *L); 
    void AfficherCoordonnees(Coordonnees *C); 
    void AfficheMot(mots *mot); 
    char *dernierMot(Liste *p); 
    unsigned int HashCode (char *ligne);
    void AfficherTableHash(Liste **TableHash); 
    unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot); 
    void PosLigne(FILE *F,Liste **TableHash); 
    void frequent( Liste **TableHash , int mc); 
    void ParcourirElementTableHash(Liste **TableHash,char *mot); 
    void FiltreListe(Liste **L, int seuil); 
    void Generer2seq(Liste **TableHash, int seuil, Liste **seq); 
    Liste * GenererNseq(Liste **TableHash, int seuil,Liste **se, Liste **seq); 
    void GenRA(Liste * l, Liste **TableHash); 
    void elagage(Liste *t, Liste **s); 
    int calculFrequence(Liste **TableHash, char mot[50]); 
    Liste* supprimerElement(Liste* liste, Liste* sup); 
    void Verifier(Liste **L); 
    int MaxPos(Liste **TableHash,char mot[50],int ligne); 
    Coordonnees* supprimerCooredonnees(Coordonnees* liste, Coordonnees* sup) ;
    mots *InsertionEnQueueMot(mots *m,char mot[50]);
     
    void rassembler (Liste** L);
    #endif
    Fichiers attachés Fichiers attachés
    Le jour est le père du labeur et la nuit est la mère des pensées.

  5. #5
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    ok
    OK. Ceci fonctionne
    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
     
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include <assert.h>
     
    #define TAILLEHASH 307
     
    typedef struct c
    {
       int pos;
       int nl;
       struct c *suivant;
    }
    Coordonnees;
     
    typedef struct m
    {
       char mot[50];
       struct m *suivant;
    }
    mots;
     
    typedef struct L2
    {
       int freq;
       mots *m;
       Coordonnees *c;
       struct L2 *suivant;
    }
    Liste;
     
    static unsigned int HashCode (char const *ligne)
    {
       unsigned int Code = 0;
       size_t const len = strlen (ligne);
       size_t i;
     
       printf ("ligne = '%s'\n", ligne);
     
       for (i = 0; i < len; i++)
       {
          Code = ligne[i] + 31 * Code;
       }
       return Code % 101;
    }
     
    static unsigned int ChercherMotDansTableHash (Liste ** TableHash,
                                                  char const *mot)
    {
       int found = 0;
       unsigned int cle = HashCode (mot);
       Liste *p;
       assert (cle < TAILLEHASH);
       for (p = TableHash[cle]; !found && p != NULL; p = p->suivant)
       {
     
          printf ("p=%p\n", (void *) p);
          assert (p != NULL);
          assert (p->m != NULL);
          assert (p->m->mot != NULL);
          found = strcmp (p->m->mot, mot) == 0;
       }
       return found;
    }
     
    int main (void)
    {
       Liste **TableHash = malloc (TAILLEHASH * sizeof *TableHash);
       if (TableHash != NULL)
       {
          unsigned int pt = HashCode (".");
          {
             int i;
             for (i = 0; i < TAILLEHASH; ++i)
                TableHash[i] = NULL;
          }
     
          printf ("debut du programme \n" "----------------------------------\n");
     
          {
             FILE *F = fopen ("essai.txt", "r");
             if (F != NULL)
             {
                char mot[100];
     
                printf
                   ("Ouverture du Fichier \n"
                    "----------------------------------\n");
                while (fscanf (F, "%s", mot) == 1)
                {
                   unsigned int cle = HashCode (mot);
                   printf ("%u-", cle);
                   assert (mot != NULL);
                   assert (TableHash != NULL);
     
                   if ((cle != pt)
                       && (!ChercherMotDansTableHash (TableHash, mot)))
                   {
                      printf ("fghf");
                   }
                   printf ("\n");
                }
                fclose (F);
             }
          }
       }
       return 0;
    }
    Le problème était le type de la cle qui doit toujours être unsigned int, notamment dans HashCode () (corrigé) ... sinon, on a des valeurs négatives reconverties en unsigned et ça part en vrille...

    Attention, rien n'est mis dans la liste chainée. La recherche est donc vaine...
    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
     
    ligne = '.'
    debut du programme
    ----------------------------------
    Ouverture du Fichier
    ----------------------------------
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'du'
    86-ligne = 'du'
    fghf
    ligne = 'monde'
    11-ligne = 'monde'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = 'of'
    8-ligne = 'of'
    fghf
    ligne = 'world'
    34-ligne = 'world'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'ma'
    42-ligne = 'ma'
    fghf
    ligne = 'famille'
    3-ligne = 'famille'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'family'
    95-ligne = 'family'
    fghf
    ligne = '.'
    46-
    ligne = 'j'ai'
    70-ligne = 'j'ai'
    fghf
    ligne = 'deux'
    14-ligne = 'deux'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'i'
    4-ligne = 'i'
    fghf
    ligne = 'have'
    4-ligne = 'have'
    fghf
    ligne = 'two'
    35-ligne = 'two'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'ils'
    35-ligne = 'ils'
    fghf
    ligne = 'sont'
    51-ligne = 'sont'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'they'
    15-ligne = 'they'
    fghf
    ligne = 'are'
    94-ligne = 'are'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friend'
    58-ligne = 'friend'
    fghf
    ligne = '.'
    46-
     
    Process returned 0 (0x0)   execution time : 0.174 s
    Press any key to continue.
    Pas de Wi-Fi à la maison : CPL

  6. #6
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    Merci ED,
    c'est gentil de ta part
    Le jour est le père du labeur et la nuit est la mère des pensées.

  7. #7
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    Citation Envoyé par Emmanuel Delahaye Voir le message
    OK. Ceci fonctionne
    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
     
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include <assert.h>
     
    #define TAILLEHASH 307
     
    typedef struct c
    {
       int pos;
       int nl;
       struct c *suivant;
    }
    Coordonnees;
     
    typedef struct m
    {
       char mot[50];
       struct m *suivant;
    }
    mots;
     
    typedef struct L2
    {
       int freq;
       mots *m;
       Coordonnees *c;
       struct L2 *suivant;
    }
    Liste;
     
    static unsigned int HashCode (char const *ligne)
    {
       unsigned int Code = 0;
       size_t const len = strlen (ligne);
       size_t i;
     
       printf ("ligne = '%s'\n", ligne);
     
       for (i = 0; i < len; i++)
       {
          Code = ligne[i] + 31 * Code;
       }
       return Code % 101;
    }
     
    static unsigned int ChercherMotDansTableHash (Liste ** TableHash,
                                                  char const *mot)
    {
       int found = 0;
       unsigned int cle = HashCode (mot);
       Liste *p;
       assert (cle < TAILLEHASH);
       for (p = TableHash[cle]; !found && p != NULL; p = p->suivant)
       {
     
          printf ("p=%p\n", (void *) p);
          assert (p != NULL);
          assert (p->m != NULL);
          assert (p->m->mot != NULL);
          found = strcmp (p->m->mot, mot) == 0;
       }
       return found;
    }
     
    int main (void)
    {
       Liste **TableHash = malloc (TAILLEHASH * sizeof *TableHash);
       if (TableHash != NULL)
       {
          unsigned int pt = HashCode (".");
          {
             int i;
             for (i = 0; i < TAILLEHASH; ++i)
                TableHash[i] = NULL;
          }
     
          printf ("debut du programme \n" "----------------------------------\n");
     
          {
             FILE *F = fopen ("essai.txt", "r");
             if (F != NULL)
             {
                char mot[100];
     
                printf
                   ("Ouverture du Fichier \n"
                    "----------------------------------\n");
                while (fscanf (F, "%s", mot) == 1)
                {
                   unsigned int cle = HashCode (mot);
                   printf ("%u-", cle);
                   assert (mot != NULL);
                   assert (TableHash != NULL);
     
                   if ((cle != pt)
                       && (!ChercherMotDansTableHash (TableHash, mot)))
                   {
                      printf ("fghf");
                   }
                   printf ("\n");
                }
                fclose (F);
             }
          }
       }
       return 0;
    }
    Le problème était le type de la cle qui doit toujours être unsigned int, notamment dans HashCode () (corrigé) ... sinon, on a des valeurs négatives reconverties en unsigned et ça part en vrille...

    Attention, rien n'est mis dans la liste chainée. La recherche est donc vaine...
    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
     
    ligne = '.'
    debut du programme
    ----------------------------------
    Ouverture du Fichier
    ----------------------------------
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'du'
    86-ligne = 'du'
    fghf
    ligne = 'monde'
    11-ligne = 'monde'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = 'of'
    8-ligne = 'of'
    fghf
    ligne = 'world'
    34-ligne = 'world'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'ma'
    42-ligne = 'ma'
    fghf
    ligne = 'famille'
    3-ligne = 'famille'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'family'
    95-ligne = 'family'
    fghf
    ligne = '.'
    46-
    ligne = 'j'ai'
    70-ligne = 'j'ai'
    fghf
    ligne = 'deux'
    14-ligne = 'deux'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'i'
    4-ligne = 'i'
    fghf
    ligne = 'have'
    4-ligne = 'have'
    fghf
    ligne = 'two'
    35-ligne = 'two'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'ils'
    35-ligne = 'ils'
    fghf
    ligne = 'sont'
    51-ligne = 'sont'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'they'
    15-ligne = 'they'
    fghf
    ligne = 'are'
    94-ligne = 'are'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friends'
    81-ligne = 'friends'
    fghf
    ligne = '.'
    46-
    ligne = 'bonjour'
    74-ligne = 'bonjour'
    fghf
    ligne = 'mes'
    26-ligne = 'mes'
    fghf
    ligne = 'amis'
    65-ligne = 'amis'
    fghf
    ligne = 'good'
    13-ligne = 'good'
    fghf
    ligne = 'morning'
    72-ligne = 'morning'
    fghf
    ligne = 'my'
    66-ligne = 'my'
    fghf
    ligne = 'friend'
    58-ligne = 'friend'
    fghf
    ligne = '.'
    46-
     
    Process returned 0 (0x0)   execution time : 0.174 s
    Press any key to continue.
    conflicting types for 'HashCode'

    previous declaration of 'HashCode' was here
    t'a une idée ?
    Le jour est le père du labeur et la nuit est la mère des pensées.

  8. #8
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    conflicting types for 'HashCode'

    previous declaration of 'HashCode' was here
    t'a une idée ?
    Oui

    1 - retirer le 'static'
    2 - ajouter le 'const' dans le .h
    Pas de Wi-Fi à la maison : CPL

  9. #9
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    Citation Envoyé par Emmanuel Delahaye Voir le message
    Oui

    1 - retirer le 'static'
    2 - ajouter le 'const' dans le .h
    les erreurs persistent
    voila mes fichiers
    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
    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h> 
     
    #include "table_hash.h" 
    #define TAILLEHASH 307 
    #define NBRSEQ 10 
    #define SEUIL 3 
    #define SEUIL 3 
     
    int main (void)
    {   unsigned int pt;
       Liste **TableHash = malloc (TAILLEHASH * sizeof *TableHash);
       if (TableHash != NULL)
       {
          pt = HashCode (".");
          {
             int i;
             for (i = 0; i < TAILLEHASH; ++i)
                TableHash[i] = NULL;
          }
     
          printf ("debut du programme \n" "----------------------------------\n");
     
          {
             FILE *F = fopen ("essai.txt", "r");
             if (F != NULL)
             {
                char mot[100];
     
                printf
                   ("Ouverture du Fichier \n"
                    "----------------------------------\n");
                while (fscanf (F, "%s", mot) == 1)
                {
                   unsigned int cle = HashCode (mot);
                   printf ("%u-", cle);
                   assert (mot != NULL);
                   assert (TableHash != NULL);
     
                   if ((cle != pt)
                       && (!ChercherMotDansTableHash (TableHash, mot)))
                   {
                      printf ("fghf");
                   }
                   printf ("\n");
                }
                fclose (F);
             }
          }
       }
       return 0;
    }
     
     
     unsigned int HashCode (char  *ligne)
    {
       unsigned int Code = 0;
       size_t const len = strlen (ligne);
       size_t i;
     
       printf ("ligne = '%s'\n", ligne);
     
       for (i = 0; i < len; i++)
       {
          Code = ligne[i] + 31 * Code;
       }
       return Code % 101;
    }
     
     unsigned int ChercherMotDansTableHash (Liste ** TableHash,char const *mot)
    {
       int found = 0;
       unsigned int cle = HashCode (mot);
       Liste *p;
       assert (cle < TAILLEHASH);
       for (p = TableHash[cle]; !found && p != NULL; p = p->suivant)
       {
     
          printf ("p=%p\n", (void *) p);
          assert (p != NULL);
          assert (p->m != NULL);
          assert (p->m->mot != NULL);
          found = strcmp (p->m->mot, mot) == 0;
       }
       return found;
    }
    mots *InsertionEnTeteMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = m; 
     
    	return nouveau; 
    }
    Liste *InsertionEnTete(Liste *L,char *mot){ 
    	Liste *nouveau; 
    	nouveau = (Liste *) malloc (sizeof(Liste)); 
    	nouveau->freq=0; 
    	nouveau->m=NULL; 
    	nouveau->m=InsertionEnTeteMot(nouveau->m,mot); 
    	nouveau->m = InsertionEnQueueMot(nouveau->m,mot);
    	nouveau->suivant = L; 
    	nouveau->c = NULL; 
    	return nouveau; 
    } 
    mots *InsertionEnQueueMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = NULL; 
     
    	if(m==NULL)
    		return nouveau; 
    	else
    	{
    		m->suivant = nouveau;
    		return m;
    	}
    }
    le header
    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
    #ifndef TABLE_HASH 
    #define TABLE_HASH 
     
    typedef struct c{ 
    	int pos; 
    	int nl; 
    	struct c *suivant; 
    }Coordonnees; 
     
    typedef struct L{ 
    	char  mot[50]; 
    	Coordonnees *c; 
    	struct L *suivant; 
    }Liste1; 
     
    typedef struct m{ 
    	char mot[50]; 
    	struct m *suivant; 
    }mots; 
     
    typedef struct L2{ 
        int freq; 
    	mots *m; 
    	Coordonnees *c; 
    	struct L2 *suivant; 
    }Liste; 
     
    int nb_lignes (FILE *fp) 
    { 
      int n=0; 
      char c; 
     
      while ((c = fgetc(fp)) != EOF) 
      { 
        if (c == '\n') 
        { 
          n++; 
        } 
      } 
      return n; 
    } 
     
     
     
    Liste *InsertionEnTete(Liste *L,char *mot); 
    Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos); 
    mots *InsertionEnTeteMot(mots *m,char mot[50]); 
    void AfficherListe(Liste *L); 
    void AfficherCoordonnees(Coordonnees *C); 
    void AfficheMot(mots *mot); 
    char *dernierMot(Liste *p); 
    const unsigned int HashCode (char *ligne);
    void AfficherTableHash(Liste **TableHash); 
    const unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot); 
    void PosLigne(FILE *F,Liste **TableHash); 
    void frequent( Liste **TableHash , int mc); 
    void ParcourirElementTableHash(Liste **TableHash,char *mot); 
    void FiltreListe(Liste **L, int seuil); 
    void Generer2seq(Liste **TableHash, int seuil, Liste **seq); 
    Liste * GenererNseq(Liste **TableHash, int seuil,Liste **se, Liste **seq); 
    void GenRA(Liste * l, Liste **TableHash); 
    void elagage(Liste *t, Liste **s); 
    int calculFrequence(Liste **TableHash, char mot[50]); 
    Liste* supprimerElement(Liste* liste, Liste* sup); 
    void Verifier(Liste **L); 
    int MaxPos(Liste **TableHash,char mot[50],int ligne); 
    Coordonnees* supprimerCooredonnees(Coordonnees* liste, Coordonnees* sup) ;
    mots *InsertionEnQueueMot(mots *m,char mot[50]);
     
    void rassembler (Liste** L);
    #endif
    merci
    ya toujours les meme erreurs
    Le jour est le père du labeur et la nuit est la mère des pensées.

  10. #10
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    les erreurs persistent
    voila mes fichiers
    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
     
    #include "table_hash.h" 
    <...>
     unsigned int HashCode (char  *ligne)
    {
       unsigned int Code = 0;
       size_t const len = strlen (ligne);
       size_t i;
     
       printf ("ligne = '%s'\n", ligne);
     
       for (i = 0; i < len; i++)
       {
          Code = ligne[i] + 31 * Code;
       }
       return Code % 101;
    }
    le header
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    #ifndef TABLE_HASH 
    #define TABLE_HASH 
    <...>
    unsigned int HashCode (char *ligne);
    #endif
    J'ai retiré le const (je pensais à autre chose). Ce devrait marcher comme ça.
    Pas de Wi-Fi à la maison : CPL

  11. #11
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    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
     unsigned int ChercherMotDansTableHash (Liste ** TableHash,char const *mot)
    {
       int found = 0;
       unsigned int cle = HashCode (mot);
       Liste *p;
       assert (cle < TAILLEHASH);
       for (p = TableHash[cle]; !found && p != NULL; p = p->suivant)
       {
     
          printf ("p=%p\n", (void *) p);
          assert (p != NULL);
          assert (p->m != NULL);
          assert (p->m->mot != NULL);
          found = strcmp (p->m->mot, mot) == 0;
       }
       return found;
    }
    4 erreurs:
    conflicting types for 'ChercherMotDansTableHash' .
    previous declaration of 'ChercherMotDansTableHash' was here
    conflicting types for 'ChercherMotDansTableHash'
    previous declaration of 'ChercherMotDansTableHash' was here

    Le jour est le père du labeur et la nuit est la mère des pensées.

  12. #12
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    merci ED,
    mais ya d'autre erreurs au niveau du mot "assert"
    more undefined references to `assert' follow
    [Linker error] undefined reference to `assert'
    t'as une idée.? merci
    Le jour est le père du labeur et la nuit est la mère des pensées.

  13. #13
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    OK c'est bon.
    merci ED
    Le jour est le père du labeur et la nuit est la mère des pensées.

  14. #14
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    Bonjour tout le monde,
    J'ai developpé une fonction "InsertionEnTete(TableHash[cle],mot)" qui rempli ta table de hacahge avec les mots, pour le mement ya pas de probleme sauf que dans l'affichage , elle m'affiche :
    bonjour bonjour
    le le
    monde monde.
    je vois pas pourquoi il m'affiche 2fois le mots successivement.
    tu peux m'aider STp
    merci
    Le jour est le père du labeur et la nuit est la mère des pensées.

  15. #15
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    Bonjour ED,
    <...>
    tu peux m'aider STp
    Sans code, non. Et je rappelle que tu es sur un forum public. Ne pas faire de demandes personnalisées...
    Pas de Wi-Fi à la maison : CPL

  16. #16
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    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
    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
    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h> 
    #include<assert.h>
     
     
    #include "table_hash.h" 
    #define TAILLEHASH 307 
    #define NBRSEQ 10 
    #define SEUIL 3 
    #define SEUIL 3 
     
    int main (void)
     
    {   unsigned int pt;
    char c;
       Liste **TableHash = malloc (TAILLEHASH * sizeof *TableHash);
       if (TableHash != NULL)
       {
          pt = HashCode (".");
          {
             int i;
             for (i = 0; i < TAILLEHASH; ++i)
                TableHash[i] = NULL;
          }
     
          printf ("debut du programme \n" "----------------------------------\n");
     
          {
             FILE *F = fopen ("C:\\essai.txt", "r");
             if (F != NULL)
             {
                char mot[100];
     
                printf
                   ("Ouverture du Fichier \n"
                    "----------------------------------\n");
                while (fscanf (F, "%s", mot) == 1)
                {
                   unsigned int cle = HashCode (mot);
                  printf ("%u-", cle);
                  assert (mot != NULL);
                   assert (TableHash != NULL);
     
                   if ((cle != pt)&& (!ChercherMotDansTableHash (TableHash, mot)))
                   {
     
                      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
     
     
     
                   }
                   printf ("\n");
                }
                fclose (F);
                F=fopen("C:\\essai.txt","r"); 
    	        PosLigne(F,TableHash);
    	        AfficherTableHash(TableHash);
             }
          }
       }
       scanf("%s",c);
       return 0;
     
    }
     
     
    unsigned int HashCode (char  *ligne)
    {
       unsigned int Code = 0;
       size_t const len = strlen (ligne);
       size_t i;
     
     //  printf ("ligne = '%s'\n", ligne);
     
       for (i = 0; i < len; i++)
       {
          Code = ligne[i] + 31 * Code;
       }
       return Code % 101;
    }
     
     
     unsigned int ChercherMotDansTableHash (Liste ** TableHash,char *mot)
    {
       int found = 0;
       unsigned int cle = HashCode (mot);
       Liste *p;
       assert (cle < TAILLEHASH);
       for (p = TableHash[cle]; !found && p != NULL; p = p->suivant)
       {
     
         // printf ("p=%p\n", (void *) p);
          assert (p != NULL);
         assert (p->m != NULL);
          assert (p->m->mot != NULL);
          found = strcmp (p->m->mot, mot) == 0;
       }
       return found;
    }
    mots *InsertionEnTeteMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = m; 
     
    	return nouveau; 
    }
    Liste *InsertionEnTete(Liste *L,char *mot){ 
    	Liste *nouveau; 
    	nouveau = (Liste *) malloc (sizeof(Liste)); 
    	nouveau->freq=0; 
    	nouveau->m=NULL; 
    	nouveau->m=InsertionEnTeteMot(nouveau->m,mot); 
    	nouveau->m = InsertionEnQueueMot(nouveau->m,mot);
    	nouveau->suivant = L; 
    	nouveau->c = NULL; 
    	return nouveau; 
    } 
    mots *InsertionEnQueueMot(mots *m,char mot[50]){ 
    	mots *nouveau; 
    	nouveau = (mots *) malloc (sizeof(mots)); 
    	strcpy(nouveau->mot,mot); 
    	nouveau->suivant = NULL; 
     
    	if(m==NULL)
    		return nouveau; 
    	else
    	{
    		m->suivant = nouveau;
    		return m;
    	}
    } 
    void PosLigne(FILE *F,Liste **TableHash)  
    {   
    	char s[50];   
    	int nl,pos,i;   
    	Liste *p;   
    	Coordonnees *c;   
    	int trouve =0;   
    	nl=pos=1;   
    	for(i=0;i<TAILLEHASH;++i)   
    		if(TableHash[i]!=NULL)   
    			for(p=TableHash[i];p!=NULL;p=p->suivant)   
    			p->freq=0; 
    			while(fscanf(F,"%s",s)==1)  
    			{   
    				for(i=0;i<TAILLEHASH;++i)   
    				{  
    					if(TableHash[i]!=NULL)   
    					{  
    						for(p=TableHash[i];p!=NULL;p=p->suivant)   
    						{  
    							Coordonnees *x;//ou Coordonnees x; sans le *  
    							if(strcmp(p->m->mot,s)==0)   
    							{
     
    								/*Avant l'insertion*/  
    								trouve=0; 
    								for(x=p->c;x!=NULL;x=x->suivant)   
    									if(x->nl == nl) //même ligne   
    										trouve=1;   
    									if(trouve==0)   
    										p->freq=p->freq+1;    
    									p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);    
    							}   
    						}   
    					}  
    				}  
    				/*ici :p*/  
    				if(fgetc(F)=='\n')  
    				{   
    					++nl; // ou nl++; ça change rien  
    					pos=0;   
    				}   
    				++pos;//pareil ou pos++; ça change rien non plus  
    			}  
    } 
    Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl ,int pos){ 
    	Coordonnees *nouveau; 
    	nouveau = (Coordonnees *) malloc (sizeof(Coordonnees)); 
    	nouveau->pos = pos; 
    	nouveau->nl = nl; 
    	nouveau->suivant = C; 
    	return nouveau; 
    } 
    void AfficherTableHash(Liste **TableHash){ 
    	int i; 
    	for(i=0;i<TAILLEHASH;++i) 
    		if(TableHash[i] != NULL){ 
    			printf("Conteneur %d \n",i); 
    			AfficherListe(TableHash[i]); 
    			printf("----------------------------------\n"); 
    		} 
    } 
    void AfficherListe(Liste *L){ 
    	Liste *p; 
    	for(p=L;p!=NULL;p=p->suivant){ 
    		AfficheMot(p->m); 
    		printf("%d : ",p->freq); 
    		AfficherCoordonnees(p->c); 
    	} 
    } 
    void AfficheMot(mots *m){ 
    	mots *p; 
    	for(p=m;p!=NULL;p=p->suivant) 
    		printf("%s ",p->mot); 
    	printf("\n"); 
    	/*if(m!=NULL)
    	{
    		AfficheMot(m->suivant);
    		printf("%s ",m->mot);
    	}*/
     
     
    } 
    void AfficherCoordonnees(Coordonnees *C){ 
    	Coordonnees *p; 
    	for(p=C;p!=NULL;p=p->suivant) 
    		printf(" (%d,%d) ",p->nl,p->pos); 
    	printf("\n"); 
    }
    et ca le header
    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
    #ifndef TABLE_HASH 
    #define TABLE_HASH 
     
    typedef struct c{ 
    	int pos; 
    	int nl; 
    	struct c *suivant; 
    }Coordonnees; 
     
    typedef struct L{ 
    	char  mot[50]; 
    	Coordonnees *c; 
    	struct L *suivant; 
    }Liste1; 
     
    typedef struct m{ 
    	char mot[50]; 
    	struct m *suivant; 
    }mots; 
     
    typedef struct L2{ 
        int freq; 
    	mots *m; 
    	Coordonnees *c; 
    	struct L2 *suivant; 
    }Liste; 
     
    int nb_lignes (FILE *fp) 
    { 
      int n=0; 
      char c; 
     
      while ((c = fgetc(fp)) != EOF) 
      { 
        if (c == '\n') 
        { 
          n++; 
        } 
      } 
      return n; 
    } 
     
     
     
    Liste *InsertionEnTete(Liste *L,char *mot); 
    Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos); 
    mots *InsertionEnTeteMot(mots *m,char mot[50]); 
    void AfficherListe(Liste *L); 
    void AfficherCoordonnees(Coordonnees *C); 
    void AfficheMot(mots *mot); 
    char *dernierMot(Liste *p); 
    unsigned int HashCode (char *ligne);
    void AfficherTableHash(Liste **TableHash); 
    unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot); 
    void PosLigne(FILE *F,Liste **TableHash); 
    void frequent( Liste **TableHash , int mc); 
    void ParcourirElementTableHash(Liste **TableHash,char *mot); 
    void FiltreListe(Liste **L, int seuil); 
    void Generer2seq(Liste **TableHash, int seuil, Liste **seq); 
    Liste * GenererNseq(Liste **TableHash, int seuil,Liste **se, Liste **seq); 
    void GenRA(Liste * l, Liste **TableHash); 
    void elagage(Liste *t, Liste **s); 
    int calculFrequence(Liste **TableHash, char mot[50]); 
    Liste* supprimerElement(Liste* liste, Liste* sup); 
    void Verifier(Liste **L); 
    int MaxPos(Liste **TableHash,char mot[50],int ligne); 
    Coordonnees* supprimerCooredonnees(Coordonnees* liste, Coordonnees* sup) ;
    mots *InsertionEnQueueMot(mots *m,char mot[50]);
     
    void rassembler (Liste** L);
    #endif
    merci
    Le jour est le père du labeur et la nuit est la mère des pensées.

  17. #17
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2004
    Messages
    304
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2004
    Messages : 304
    Points : 405
    Points
    405
    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
     
    Liste *InsertionEnTete(Liste *L,char *mot)
    { 
      Liste *nouveau; 
      nouveau = (Liste *) malloc (sizeof(Liste)); 
      nouveau->freq=0; 
      nouveau->m=NULL; 
      nouveau->m=InsertionEnTeteMot(nouveau->m,mot); 
      //nouveau->m = InsertionEnQueueMot(nouveau->m,mot);
      //le mot on l'inserre en Queue ou En tete, et non les deux ;)
      nouveau->suivant = L; 
      nouveau->c = NULL; 
      return nouveau; 
    }
    S'il n'y a pas de Solution, c'est qu'il n'y a pas de Problème.
    ----------------------------------------------------------------------------------------
    Pour se protéger, un bon préservatif pour votre PC : AntiVir et SpyBot - Search & Destroy

  18. #18
    Débutant Avatar de étoile de mer
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    978
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 978
    Points : 117
    Points
    117
    Par défaut
    Bonjour à tous
    Dans mon code ya une fonction qui plante mon programme,
    j'ai selectionné le bout du code où il ya le bug pour faciliter les choses,
    en fait j'ai une table de hachage qui contient des mot et chaque mot o une liste de ses coordonnée(liste chainée)
    donc cette fonction parcourt les elemnt de la table et teste si les mots sont differents.
    si c'est le cas ya un pointuer qui va se pointer su la teste de la liste du 1er mot et un autre sur la tete du 2eme.
    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
    void Generer2seq(Liste **TableHash)
    {
      int cpt=0;     
      int i, j;   
      Liste *p1 = malloc(TAILLEHASH * sizeof *TableHash); // element courant lors du parcours de la th
      Liste *p2 = malloc (TAILLEHASH * sizeof *TableHash);  // elemnt qui va parcourir la th
      Liste *t;
      Liste *current_ptr_coord;
      Liste *other_ptr_coord;
     
      for(i=0;i<TAILLEHASH;++i) 
    		if(TableHash[i] != NULL) 
    			for(p1=TableHash[i];p1!=NULL;p1=p1->suivant) 
    				for(j=i;j<TAILLEHASH;++j) 
    					if(TableHash[j] != NULL){ 
    						if (j==i) 
    							t=p1; 
    						else 
    							t=TableHash[j]; 
                            }
     
    						for(p2=t;p2!=NULL;p2=p2->suivant){ 
     
    							if (strcmp(p1->m->mot,p2->m->mot)!=0){   // si 2 mots differents trouvés 
                                  current_ptr_coord=p1->c;
                                  other_ptr_coord=p2->c;
                                   }
                                   }
                                   }
    merci
    Le jour est le père du labeur et la nuit est la mère des pensées.

  19. #19
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par cyrine Voir le message
    Bonjour à tous
    Dans mon code ya une fonction qui plante mon programme,
    j'ai selectionné le bout du code où il ya le bug pour faciliter les choses,
    Ca ne facilite rien du tout. On est censés faire quoi avec ça :
    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
     
     
    -------------- Build: Debug in hello ---------------
     
    Compiling: main.c
    C:\dev\hello\main.c:1: error: syntax error before '*' token
    C:\dev\hello\main.c:2: warning: function declaration isn't a prototype
    C:\dev\hello\main.c: In function `Generer2seq':
    C:\dev\hello\main.c:5: error: `Liste' undeclared (first use in this function)
    C:\dev\hello\main.c:5: error: (Each undeclared identifier is reported only once
    C:\dev\hello\main.c:5: error: for each function it appears in.)
    C:\dev\hello\main.c:5: error: `p1' undeclared (first use in this function)
    C:\dev\hello\main.c:5: warning: implicit declaration of function `malloc'
    C:\dev\hello\main.c:5: error: `TAILLEHASH' undeclared (first use in this function)
    C:\dev\hello\main.c:5: error: `TableHash' undeclared (first use in this function)
    C:\dev\hello\main.c:5: error: syntax error before '/' token
    C:\dev\hello\main.c:8: error: `current_ptr_coord' undeclared (first use in this function)
    C:\dev\hello\main.c:9: error: `other_ptr_coord' undeclared (first use in this function)
    C:\dev\hello\main.c:12: error: `NULL' undeclared (first use in this function)
    C:\dev\hello\main.c:17: error: `t' undeclared (first use in this function)
    C:\dev\hello\main.c:22: error: `p2' undeclared (first use in this function)
    C:\dev\hello\main.c:24: warning: implicit declaration of function `strcmp'
    C:\dev\hello\main.c:24: error: syntax error before '/' token
    C:\dev\hello\main.c:24: error: stray '\233' in program
    C:\dev\hello\main.c:3: warning: unused variable `cpt'
    Process terminated with status 1 (0 minutes, 0 seconds)
    15 errors, 4 warnings
    Il faut poster le code minimum compilable qui montre le problème (c'est d'ailleurs une technique de résolution de problèmes bien connue).

    Et c'est quoi cette présentation de code atroce ? C'est dur de faire ça correctement ?
    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
     
    void Generer2seq (Liste ** TableHash)
    {
       int cpt = 0;
       int i, j;
       Liste *p1 = malloc (TAILLEHASH * sizeof *TableHash); // element courant lors du parcours de la th
       Liste *p2 = malloc (TAILLEHASH * sizeof *TableHash); // elemnt qui va parcourir la th
       Liste *t;
       Liste *current_ptr_coord;
       Liste *other_ptr_coord;
     
       for (i = 0; i < TAILLEHASH; ++i)
          if (TableHash[i] != NULL)
             for (p1 = TableHash[i]; p1 != NULL; p1 = p1->suivant)
                for (j = i; j < TAILLEHASH; ++j)
                   if (TableHash[j] != NULL)
                   {
                      if (j == i)
                         t = p1;
                      else
                         t = TableHash[j];
                   }
     
       for (p2 = t; p2 != NULL; p2 = p2->suivant)
       {
     
          if (strcmp (p1->m->mot, p2->m->mot) != 0)
          {                         // si 2 mots differents trouvés
             current_ptr_coord = p1->c;
             other_ptr_coord = p2->c;
          }
       }
    }
    Pas de Wi-Fi à la maison : CPL

  20. #20
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2004
    Messages
    304
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2004
    Messages : 304
    Points : 405
    Points
    405
    Par défaut
    doucement ça reste une débutante
    et puis les fichiers nécessaires à la compilation se trouvent au début du poste .

    d'un autre coté, la présentation du code laisse à désirer

    Pour en revenir à la question, il manquerai juste { }, enfin en ce qui concerne l'esprit de l'algorithme.
    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
     
     
    void Generer2seq (Liste ** TableHash)
    {
       int cpt = 0;
       int i, j;
       Liste *p1 = malloc (TAILLEHASH * sizeof *TableHash);
       Liste *p2 = malloc (TAILLEHASH * sizeof *TableHash);
       Liste *t;
       Liste *current_ptr_coord;
       Liste *other_ptr_coord;
     
       for (i = 0; i < TAILLEHASH; ++i)
          if (TableHash[i] != NULL)
             for (p1 = TableHash[i]; p1 != NULL; p1 = p1->suivant)
                for (j = i; j < TAILLEHASH; ++j)
                {//celui là
                   if (TableHash[j] != NULL)
                   {
                      if (j == i)
                         t = p1;
                      else
                         t = TableHash[j];
                   }
     
                   for (p2 = t; p2 != NULL; p2 = p2->suivant)
                   {
                      if (strcmp (p1->m->mot, p2->m->mot) != 0)
                      {                         // si 2 mots differents trouvés
                         current_ptr_coord = p1->c;
                         other_ptr_coord = p2->c;
                      }
                   }
                }//et là
    }
    S'il n'y a pas de Solution, c'est qu'il n'y a pas de Problème.
    ----------------------------------------------------------------------------------------
    Pour se protéger, un bon préservatif pour votre PC : AntiVir et SpyBot - Search & Destroy

Discussions similaires

  1. [GD] fonction createimagefromjpeg qui plante mon site
    Par dimainfo dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 13/07/2010, 13h10
  2. Exception dans kernel32.dll qui freeze mon programme
    Par Chekov dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 30/03/2009, 13h59
  3. Ma souris logitech m'a planté mon programme!
    Par lima64 dans le forum Visual C++
    Réponses: 0
    Dernier message: 08/02/2009, 01h50
  4. fonction qui plante
    Par étoile de mer dans le forum Débuter
    Réponses: 3
    Dernier message: 19/09/2008, 09h42
  5. Erreur qui bloque mon programme
    Par bugland dans le forum Langage
    Réponses: 6
    Dernier message: 21/12/2006, 22h32

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