Pb de compilation code C table hachage

Bonjour,
j'ai un probleme
mon programme: creer une table de hachage afiin de stocker des liste d'information

typedef struct L {
char mot[100];
char donnee[100];
struct L *next;
}Liste;

struct HashTable {
int mod; // Nombre d'éléments de la table
Liste *table; // Pointeur sur la table allouée
};

// déclaration des fonctions

unsigned hash_cle(char *chaine);
int fonctHachage(liste_mot* );
void hashTableInit(HashTable ht, int mod);

void hashTableInit(HashTable& ht, int mod)
{
// Nombre d'éléments de la table
ht.mod = mod;

// Allocation de la table
if ((ht.table = (Liste*) malloc(mod * sizeof(Liste))) == 0) {
fprintf(stderr, "Plus de mémoire\n");
exit(1);
}

// Initialisation de la table
// Au début toutes les listes sont vides
for (int i = 0; i < mod; i++)
ht.table[i] = 0; // Liste vide là il ya l'erreur 1
}

// Affichage complet d'une table de hachage
void hashTablePrint(HashTable& ht)
{
for (int i = 0; i < ht.mod; i++)
//if (ht.table[i] != 0) {
// printf("Entrée %d\n", i);
listePrint(ht.table[i]);
}

void listePrint(Liste l)
{
while (l != NULL) {
printf("%d : %s", l->mot, l->donnee);
l = l->next;
}
}

Bon il ya 8 erreure ;):
1- no match for 'operator=' in '*(ht->HashTable::table + (+(((unsigned int)i) * 204u))) = 0'

aidez moi svp
merci
Configuration: Windows Vista
Internet Explorer 7.0

29 réponses

Résumé de la discussion

Le problème porte sur l'initialisation d'une table de hachage et la gestion d'une liste chaînée en C/C++, avec l'erreur de compilation « no match for operator= » lors de l'assignation de 0 à ht.table. Des échanges évoquent le type de ht.table et l'allocation mémoire, car ht.table est un pointeur et ht.table[i] = 0 échoue si l'élément est une structure et non un pointeur. En parallèle, plusieurs réponses traitent les collisions, le stockage d'informations par mot (numéro de ligne et position), et l'affichage correct des résultats grâce à des vérifications avec strcmp. Une remarque utile concerne le format du fichier texte, dont les fins de ligne peuvent influencer les données stockées et l'affichage, apportant une nuance pratique à l'analyse.

Bobot (l’IA à votre service)
  1. Modérateur
    Ben, pourquoi n'utilises-tu mon code?

    chez toi je vois

    if(ChercherMotDansTableHash(TableHash,mot))
    printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot));
    else
    printf("%s inexistant dans la table de hash\n");


    et chez moi c'est

      if(ChercherMotDansTableHash(TableHash,mot))
        ParcourirElementTableHash(TableHash,mot);
      else
        printf("%s inexistant dans la table de hash\n");

    1. Bonjour LAMI,
      c'est le meme problelme meme si jai changé l'instruction comme tu ma dit.
      t'a une idée svp.
      merci
    2. Ah, c'est bon :)
      je l'ai trouvé: yavait un probleme au niveau du fichier texte ( au niveau des point finaux) ;)
      mais bref, je voudrais savoir Lami, si c la meme chose por toi pour quoi il affiche la liste des infos de chaque element dans un ordre décroissant
      Buongiorno (16,1), (14,1), (13,8), (9,1), (5,1)
      ?

      merci
    3. Bonjour Lami, est qu'on peut améliorer plus cette fonction de hachage de sorte que 2 mots n'aappartiennent au meme element de la table de hachage.
      merci
      J'attends vos réponses
      :)
  2. #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>

    #include "table_hash.h"
    #define TAILLEHASH 307

    int main()
    {
    FILE *F;
    char mot[100];
    int i;
    unsigned int cle;
    int nl, pos;
    nl=pos=1;
    char c;
    int seuil;
    Liste **L;

    Liste **TableHash;
    TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
    for(i=0;i<TAILLEHASH;++i)
    TableHash[i] = NULL;

    F=fopen("C:\\Users\\cyrine\\Documents\\text.txt","r");
    InsertionTableHash(F,TableHash);
    fclose(F);

    printf(" la liste filtré");
    printf("\n");
    printf("\n");

    AfficherTableHash(TableHash);
    printf("voila les deux séquences");
    jointure(TableHash);
    printf("Chercher mot : ");
    scanf("%s",mot);
    if(cle = ChercherMotDansTableHash(TableHash,mot))
    printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot));
    else
    printf("%s inexistant dans la table de hash\n");
    scanf("%c",c);

    return 0;
    }

    void ParcourirElementTableHash(Liste **TableHash,char *mot){
    int cle;
    Liste *p;
    cle = hash_cle(mot);

    for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(mot,p->mot) == 0){
    printf("%s : ",mot);
    AfficherCoordonnees(p->c);
    }
    }

    void jointure(Liste **TableHash){
    int i;
    Liste *p,*pp;

    for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i]!=NULL){
    for(p=TableHash[i];p!=NULL;p=p->suivant)
    for(pp=TableHash[i];pp!=NULL;pp=pp->suivant)
    if(strcmp(p->mot,pp->mot) < 0){
    if(p->c->pos < pp->c->pos)
    printf("%s %s (%d,%d) (%d,%d)\n",
    p->mot,pp->mot,
    p->c->nl,p->c->pos,
    pp->c->nl,pp->c->pos);
    else
    printf("%s %s (%d,%d) (%d,%d)\n",
    pp->mot,p->mot,
    pp->c->nl,pp->c->pos,
    p->c->nl,p->c->pos);
    }
    }
    }

    Liste *InsertionEnTete(Liste *L,char *mot){
    Liste *nouveau;
    nouveau = (Liste *) malloc (sizeof(Liste));
    strcpy(nouveau->mot,mot);
    nouveau->suivant = L;
    nouveau->c = NULL;
    return nouveau;
    }

    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 AfficherListe(Liste *L){
    Liste *p;
    for(p=L;p!=NULL;p=p->suivant){
    AfficheMot(p->mot);
    AfficherCoordonnees(p->c);
    printf("\n");
    }
    }

    void AfficherCoordonnees(Coordonnees *C){
    Coordonnees *p;
    for(p=C;p!=NULL;p=p->suivant)
    printf(" (%d,%d) ",p->nl,p->pos);
    printf("\n");
    }

    void AfficheMot(char *mot){
    printf("%s ",mot);
    }

    unsigned int hash_cle(char *mot){
    unsigned int val = 0;
    for(;*mot!='\0';++mot)
    val = *mot + 31 * val;
    return val % TAILLEHASH;
    }
    void InsertionTableHash(FILE *F, Liste **TableHash){
    int nl,pos,i;
    unsigned int cle;
    char mot[100];
    Liste *p;
    nl=pos=1;

    while(fscanf(F,"%s",mot)==1){
    cle = hash_cle(mot);

    if(! ChercherMotDansTableHash(TableHash,mot))
    TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
    for(p=TableHash[cle];p!=NULL;p=p->suivant){
    if(strcmp(p->mot,mot)==0)
    p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
    }
    if(fgetc(F)=='\n'){
    ++nl;
    pos=0;
    }
    ++pos;
    }
    }

    void AfficherTableHash(Liste **TableHash){
    int i;
    for(i=0;i<TAILLEHASH;++i)
    if(TableHash[i] != NULL){
    printf("Conteneur %d : ",i);
    AfficherListe(TableHash[i]);
    printf("-------------------------------------------------\n");
    }
    }

    unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){

    Liste *p;
    unsigned int cle;

    cle = hash_cle(mot);
    for(p=TableHash[cle];p!=NULL;p=p->suivant)
    if(strcmp(p->mot,mot)==0)
    return 1;
    return 0;
    }

    void PosLigne(FILE *F,Liste **TableHash){
    char s[50];
    int nl,pos,i;
    Liste *p;
    nl=pos=1;

    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)
    if(strcmp(p->mot,s)==0)
    p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
    if(fgetc(F)=='\n'){
    ++nl;
    pos=0;
    }
    ++pos;
    }
    printf("\n");
    }

    stp Lami essai avec ce code la et montre moi les resultats
    1. Modérateur
      chez moi j'ai bien le résultat demandé (voir en gras)

      lami20j@debian:~/trash$ ./posmot2
      Conteneur 0 :
                      che  (18,3)
                      Dio  (17,2)
                      troppa  (10,2)
      -------------------------------------------------
      Conteneur 1 :
                      manifesti  (10,5)
      -------------------------------------------------
      Conteneur 2 :
                      pieni  (16,4)
                      l'autoradio  (7,2)
                      Presidente  (6,5)
      -------------------------------------------------
      Conteneur 3 :
                      malinconia  (16,6)
                      i  (9,4)
                      finestra  (8,6)
                      destra  (7,6)
                      italiano  (4,3)
      -------------------------------------------------
      Conteneur 4 :
                      anch'io  (18,6)
                      come  (6,4)
                      al  (5,5)
                      sono  (18,5)  (4,1)
      -------------------------------------------------
      Conteneur 5 :
                      tuoi  (9,5)
                      con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
      -------------------------------------------------
      Conteneur 6 :
                      Maria  (15,2)
                      piu'  (13,2)
                      mano  (7,5)  (2,5)
      -------------------------------------------------
      Conteneur 7 :
                      sui  (10,4)
                      artisti  (9,6)
                      sempre  (13,4)  (7,3)
      -------------------------------------------------
      Conteneur 8 :
                      lo  (18,1)
                      meno  (13,5)
                      cuore  (12,3)
                      canzoni  (11,3)
                      America  (10,3)
      -------------------------------------------------
      Conteneur 9 :
                      di  (16,5)
                      sopra  (8,4)
                      canarino  (8,3)
                      nella  (7,4)
                      Italia  (14,2)  (9,2)  (5,2)
      -------------------------------------------------
      Conteneur 10 :
                      spaghetti  (5,4)
      -------------------------------------------------
      Conteneur 11 :
                      amore  (11,5)
                      gli  (16,2)  (5,3)
                      la  (8,5)  (2,2)
                      cantare  (3,2)  (1,2)
      -------------------------------------------------
      Conteneur 12 :
                      ci  (18,4)
                      buongiorno  (17,1)
                      suore  (13,6)
                      Buongiorno  (15,1)  (14,1)  (9,1)  (5,1)
      -------------------------------------------------
      Conteneur 13 :
                      dente  (5,6)
                      Lasciatemi  (3,1)
      -------------------------------------------------
      Conteneur 14 :
                      il  (12,2)
                      un  (8,2)  (6,2)  (4,2)
                      chitarra  (2,3)
      -------------------------------------------------
      Conteneur 15 :
                      occhi  (16,3)
                      le  (11,2)
                      partigiano  (6,3)
                      sciatemi  (1,1)
      -------------------------------------------------
      Conteneur 16 :
                      sai  (18,2)
                      donne  (13,3)
                      e  (8,1)  (6,1)
                      in  (2,4)
      -------------------------------------------------
      Chercher mot : piu'
      piu' :  (13,2)
      troppa che  (10,2) (18,3)
      Dio che  (17,2) (18,3)
      troppa Dio  (10,2) (17,2)
      l'autoradio pieni  (7,2) (16,4)
      pieni Presidente  (16,4) (6,5)
      l'autoradio Presidente  (7,2) (6,5)
      i malinconia  (9,4) (16,6)
      italiano i  (4,3) (9,4)
      malinconia finestra  (16,6) (8,6)
      i finestra  (9,4) (8,6)
      italiano finestra  (4,3) (8,6)
      malinconia destra  (16,6) (7,6)
      i destra  (9,4) (7,6)
      finestra destra  (8,6) (7,6)
      italiano destra  (4,3) (7,6)
      italiano malinconia  (4,3) (16,6)
      come anch'io  (6,4) (18,6)
      sono anch'io  (18,5) (18,6)
      come sono  (6,4) (18,5)
      al anch'io  (5,5) (18,6)
      come al  (6,4) (5,5)
      sono al  (18,5) (5,5)
      con tuoi  (16,1) (9,5)
      piu' Maria  (13,2) (15,2)
      Maria mano  (15,2) (7,5)
      piu' mano  (13,2) (7,5)
      sui artisti  (10,4) (9,6)
      sempre artisti  (13,4) (9,6)
      sui sempre  (10,4) (13,4)
      lo meno  (18,1) (13,5)
      lo cuore  (18,1) (12,3)
      cuore meno  (12,3) (13,5)
      lo canzoni  (18,1) (11,3)
      canzoni meno  (11,3) (13,5)
      cuore canzoni  (12,3) (11,3)
      lo America  (18,1) (10,3)
      America meno  (10,3) (13,5)
      cuore America  (12,3) (10,3)
      canzoni America  (11,3) (10,3)
      sopra di  (8,4) (16,5)
      nella di  (7,4) (16,5)
      canarino di  (8,3) (16,5)
      canarino sopra  (8,3) (8,4)
      canarino nella  (8,3) (7,4)
      sopra nella  (8,4) (7,4)
      Italia di  (14,2) (16,5)
      Italia sopra  (14,2) (8,4)
      Italia canarino  (14,2) (8,3)
      Italia nella  (14,2) (7,4)
      gli amore  (16,2) (11,5)
      la amore  (8,5) (11,5)
      cantare amore  (3,2) (11,5)
      gli la  (16,2) (8,5)
      gli cantare  (16,2) (3,2)
      cantare la  (3,2) (8,5)
      ci suore  (18,4) (13,6)
      buongiorno ci  (17,1) (18,4)
      buongiorno suore  (17,1) (13,6)
      Buongiorno ci  (15,1) (18,4)
      buongiorno Buongiorno  (17,1) (15,1)
      Buongiorno suore  (15,1) (13,6)
      Lasciatemi dente  (3,1) (5,6)
      un il  (8,2) (12,2)
      il chitarra  (12,2) (2,3)
      un chitarra  (8,2) (2,3)
      partigiano occhi  (6,3) (16,3)
      sciatemi occhi  (1,1) (16,3)
      le occhi  (11,2) (16,3)
      le partigiano  (11,2) (6,3)
      sciatemi le  (1,1) (11,2)
      sciatemi partigiano  (1,1) (6,3)
      sai donne  (18,2) (13,3)
      e donne  (8,1) (13,3)
      donne in  (13,3) (2,4)
      e sai  (8,1) (18,2)
      e in  (8,1) (2,4)
      sai in  (18,2) (2,4)
      lami20j@debian:~/trash$                     
      1. Bizarre chez moi non, il maffiche d'autres infos :(
    2. Lasciatemi cantare
      con la chitarra in mano
      Lasciatemi cantare
      sono un italiano
      Buongiorno Italia gli spaghetti al dente
      e un partigiano come Presidente
      con l'autoradio sempre nella mano destra
      e un canarino sopra la finestra
      Buongiorno Italia con i tuoi artisti
      con troppa America sui manifesti
      con le canzoni con amore
      con il cuore
      con piu' donne sempre meno suore
      Buongiorno Italia
      Buongiorno Maria
      con gli occhi pieni di malinconia
      buongiorno Dio
      lo sai che ci sono anch'io

      //////////////////////////////
      Normallement le resultat soient :
      piu'(13,2)
      1. Modérateur
        Je travaille sous linux si tu l'as remarqué ;-)
        1. ouii , c pas le cas pour moi
          conteneur 0 : piu' (5,10)
          conteneur 19 : troppa (4,9)

          ..etc
          tous les resultata sont incorrects
      2. Modérateur
        Ben, tu n'as qu'à m'afficher tes tests comme je l'ai fait ;-)
        1. comment tu fais lami pour afficher, moi les resultata s'affichesnt sur l'ecran noir :)
      3. Modérateur
        Salut,

        Je t'ai déjà demande
        le numéro de ligne ne compte pas?!

        En fait tu peux avoir pour la même clé (donc des collision) des mot qui proviennent du plusieurs lignes, d'où ma question.

        est ce que les info sur juste de chaque mot(numligne eu position)?
        je ne comprends pas

        Là il maffiche des resultats incorrects
        Montre moi, où ;-)
        1. Bonsoir Lami; et merci je m'avoir repondu,
          laà quand il maffiche la table de hacahge il m'affiche les mot , mais leurs infos(position et num ligne ) sont incorrecte.
          je comprends pas pourkoi en fait.
          Chez toi c nikel , mais chez moi il ya une chose qui cloche. :(
      4. Modérateur
        Re,

        au lieu de
        if(strcmp(p->mot,pp->mot)){

        mets
         if(strcmp(p->mot,pp->mot) < 0){
        1. Meerci LAMI, mais juste je veux verifier un truc, quand vous avez testé ce code sur ton texte, est ce que les info sur juste de chaque mot(numligne eu position)?
          merci
        2. Là il maffiche des resultats incorrects
      5. Modérateur
        Re,

        il faut num position de second mot soit plus grand que le 1er mot :" est clé " et non pas "clé est"
        le numéro de ligne ne compte pas?!

        Le fichier.
        lami20j@debian:~/trash$ cat fichier.txt
        Non Lami :)
        ben faut parcourir la table de hachage( 2 compteurs) , tester chaque avec le mot suivantselon la num ligne qui est enregistré dans la liste chaine(tu te souviens) et puis faire la jointure(calculer la clé de hachage pour stocker dans la table de hachage) ctt ;)
        tu vois?
        


        Le code
        table_hash.h
        /* table_hash.h */
        
        #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;
        }Liste;
        
        
        Liste *InsertionEnTete(Liste *L,char *mot);
        void InsertionTableHash(FILE *F, Liste **TableHash);
        void jointure(Liste **TableHash);
        Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
        void AfficherListe(Liste *L);
        void AfficherCoordonnees(Coordonnees *C);
        void AfficheMot(char *mot);
        void ParcourirElementTableHash(Liste **TableHash,char *mot);
        unsigned int hash_cle(char *mot);
        void AfficherTableHash(Liste **TableHash);
        unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
        void PosLigne(FILE *F,Liste **TableHash);
        
        #endif
        


        posmot2.c
        /* posmot2.c */
        #include<stdio.h>
        #include<stdlib.h>
        #include<string.h>
        #include<ctype.h>
        #include "table_hash.h"
        #define TAILLEHASH 17
        
        int main()
        {
          FILE *F;
          Liste **TableHash;
          char mot[100];
          int i;
        
          TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
          for(i=0;i<TAILLEHASH;++i)
            TableHash[i] = NULL;
        
          F=fopen("fichier.txt","r");
          InsertionTableHash(F,TableHash);
          fclose(F);
          AfficherTableHash(TableHash);
        
          printf("Chercher mot : ");
          scanf("%s",mot);
          if(ChercherMotDansTableHash(TableHash,mot))
            ParcourirElementTableHash(TableHash,mot);
          else
            printf("%s inexistant dans la table de hash\n");
          jointure(TableHash);
          return 0;
        }
        
        Liste *InsertionEnTete(Liste *L,char *mot){
          Liste *nouveau;
          nouveau = (Liste *) malloc (sizeof(Liste));
          strcpy(nouveau->mot,mot);
          nouveau->suivant = L;
          nouveau->c = NULL;
          return nouveau;
        }
        
        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 AfficherListe(Liste *L){
          Liste *p;
          for(p=L;p!=NULL;p=p->suivant){
            AfficheMot(p->mot);
            AfficherCoordonnees(p->c);
          }
        }
        
        void AfficherCoordonnees(Coordonnees *C){
          Coordonnees *p;
          for(p=C;p!=NULL;p=p->suivant)
        	  printf(" (%d,%d) ",p->nl,p->pos);
          printf("\n");
        }
        
        void AfficheMot(char *mot){
          printf("\t\t%s ",mot);
        }
        
        unsigned int hash_cle(char *mot){
          unsigned int val = 0;
          for(;*mot!='\0';++mot)
            val = *mot + 31 * val;
          return val % TAILLEHASH;
        }
        
        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");
            }
        }
        
        unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
          
          Liste *p;
          unsigned int cle;
          
          cle = hash_cle(mot);
          for(p=TableHash[cle];p!=NULL;p=p->suivant)
            if(strcmp(p->mot,mot)==0)
              return 1;
          return 0;
        }
        
        
        void InsertionTableHash(FILE *F, Liste **TableHash){
          int nl,pos,i;
          unsigned int cle;
          char mot[100];
          Liste *p;
          nl=pos=1;
          
          while(fscanf(F,"%s",mot)==1){
            cle = hash_cle(mot);
        
            if(! ChercherMotDansTableHash(TableHash,mot))
              TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
            for(p=TableHash[cle];p!=NULL;p=p->suivant){
                  if(strcmp(p->mot,mot)==0)
                    p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
            }
            if(fgetc(F)=='\n'){
              ++nl;
              pos=0;
            }
            ++pos;
            //printf("\n");
          }
        }
        
        void ParcourirElementTableHash(Liste **TableHash,char *mot){
          int cle;
          Liste *p;
          cle = hash_cle(mot);
        
          for(p=TableHash[cle];p!=NULL;p=p->suivant)
            if(strcmp(mot,p->mot) == 0){
              printf("%s : ",mot);
              AfficherCoordonnees(p->c);
            }
        }
        
        void jointure(Liste **TableHash){
          int i;
          Liste *p,*pp;
        
          for(i=0;i<TAILLEHASH;++i)
            if(TableHash[i]!=NULL){
              for(p=TableHash[i];p!=NULL;p=p->suivant)
                for(pp=TableHash[i];pp!=NULL;pp=pp->suivant)
                  if(strcmp(p->mot,pp->mot)){
                    if(p->c->pos < pp->c->pos)
                      printf("%s %s  (%d,%d) (%d,%d)\n",
        			  p->mot,pp->mot,
        			  p->c->nl,p->c->pos,
        			  pp->c->nl,pp->c->pos);
        	    else
                      printf("%s %s  (%d,%d) (%d,%d)\n",
        			  pp->mot,p->mot,
        			  pp->c->nl,pp->c->pos,
        			  p->c->nl,p->c->pos);
        	  }
            }
        }
        


        Le résultat
        lami20j@debian:~/trash$ gcc posmot2.c -o posmot2
        lami20j@debian:~/trash$ ./posmot2
        Conteneur 0 :
                        ;)  (2,46)
                        clé  (2,35)
                        et  (2,29)
                        est  (2,21)
                        num  (2,18)
        -------------------------------------------------
        Conteneur 1 :
                        chaine(tu  (2,26)
        -------------------------------------------------
        Conteneur 2 :
                        stocker  (2,39)
        -------------------------------------------------
        Conteneur 3 :
                        liste  (2,25)
                        :)  (1,3)
                        Non  (1,1)
        -------------------------------------------------
        Conteneur 5 :
                        puis  (2,30)
                        enregistré  (2,22)
                        de  (2,43)  (2,36)  (2,6)
        -------------------------------------------------
        Conteneur 6 :
                        faire  (2,31)
                        qui  (2,20)
                        hachage(  (2,7)
        -------------------------------------------------
        Conteneur 7 :
                        tu  (3,1)
                        hachage)  (2,44)
                        avec  (2,13)
                        table  (2,42)  (2,5)
        -------------------------------------------------
        Conteneur 8 :
                        te  (2,27)
                        suivantselon  (2,16)
                        chaque  (2,12)
                        parcourir  (2,3)
        -------------------------------------------------
        Conteneur 9 :
                        faut  (2,2)
                        ben  (2,1)
        -------------------------------------------------
        Conteneur 10 :
                        hachage  (2,37)
                        souviens)  (2,28)
                        ,  (2,10)
                        compteurs)  (2,9)
                        Lami  (1,2)
        -------------------------------------------------
        Conteneur 11 :
                        la  (2,41)  (2,34)  (2,32)  (2,24)  (2,17)  (2,4)
        -------------------------------------------------
        Conteneur 12 :
                        jointure(calculer  (2,33)
        -------------------------------------------------
        Conteneur 13 :
                        ctt  (2,45)
                        tester  (2,11)
        -------------------------------------------------
        Conteneur 15 :
                        dans  (2,40)  (2,23)
                        ligne  (2,19)
                        le  (2,14)
        -------------------------------------------------
        Conteneur 16 :
                        vois?  (3,2)
                        pour  (2,38)
                        mot  (2,15)
                        2  (2,8)
        -------------------------------------------------
        Chercher mot : mot
        mot :  (2,15)
        clé ;)  (2,35) (2,46)
        et ;)  (2,29) (2,46)
        est ;)  (2,21) (2,46)
        num ;)  (2,18) (2,46)
        clé ;)  (2,35) (2,46)
        et clé  (2,29) (2,35)
        est clé  (2,21) (2,35)
        num clé  (2,18) (2,35)
        et ;)  (2,29) (2,46)
        et clé  (2,29) (2,35)
        est et  (2,21) (2,29)
        num et  (2,18) (2,29)
        est ;)  (2,21) (2,46)
        est clé  (2,21) (2,35)
        est et  (2,21) (2,29)
        num est  (2,18) (2,21)
        num ;)  (2,18) (2,46)
        num clé  (2,18) (2,35)
        num et  (2,18) (2,29)
        num est  (2,18) (2,21)
        :) liste  (1,3) (2,25)
        Non liste  (1,1) (2,25)
        :) liste  (1,3) (2,25)
        Non :)  (1,1) (1,3)
        Non liste  (1,1) (2,25)
        Non :)  (1,1) (1,3)
        enregistré puis  (2,22) (2,30)
        puis de  (2,30) (2,43)
        enregistré puis  (2,22) (2,30)
        enregistré de  (2,22) (2,43)
        puis de  (2,30) (2,43)
        enregistré de  (2,22) (2,43)
        qui faire  (2,20) (2,31)
        hachage( faire  (2,7) (2,31)
        qui faire  (2,20) (2,31)
        hachage( qui  (2,7) (2,20)
        hachage( faire  (2,7) (2,31)
        hachage( qui  (2,7) (2,20)
        tu hachage)  (3,1) (2,44)
        tu avec  (3,1) (2,13)
        tu table  (3,1) (2,42)
        tu hachage)  (3,1) (2,44)
        avec hachage)  (2,13) (2,44)
        table hachage)  (2,42) (2,44)
        tu avec  (3,1) (2,13)
        avec hachage)  (2,13) (2,44)
        avec table  (2,13) (2,42)
        tu table  (3,1) (2,42)
        table hachage)  (2,42) (2,44)
        avec table  (2,13) (2,42)
        suivantselon te  (2,16) (2,27)
        chaque te  (2,12) (2,27)
        parcourir te  (2,3) (2,27)
        suivantselon te  (2,16) (2,27)
        chaque suivantselon  (2,12) (2,16)
        parcourir suivantselon  (2,3) (2,16)
        chaque te  (2,12) (2,27)
        chaque suivantselon  (2,12) (2,16)
        parcourir chaque  (2,3) (2,12)
        parcourir te  (2,3) (2,27)
        parcourir suivantselon  (2,3) (2,16)
        parcourir chaque  (2,3) (2,12)
        ben faut  (2,1) (2,2)
        ben faut  (2,1) (2,2)
        souviens) hachage  (2,28) (2,37)
        , hachage  (2,10) (2,37)
        compteurs) hachage  (2,9) (2,37)
        Lami hachage  (1,2) (2,37)
        souviens) hachage  (2,28) (2,37)
        , souviens)  (2,10) (2,28)
        compteurs) souviens)  (2,9) (2,28)
        Lami souviens)  (1,2) (2,28)
        , hachage  (2,10) (2,37)
        , souviens)  (2,10) (2,28)
        compteurs) ,  (2,9) (2,10)
        Lami ,  (1,2) (2,10)
        compteurs) hachage  (2,9) (2,37)
        compteurs) souviens)  (2,9) (2,28)
        compteurs) ,  (2,9) (2,10)
        Lami compteurs)  (1,2) (2,9)
        Lami hachage  (1,2) (2,37)
        Lami souviens)  (1,2) (2,28)
        Lami ,  (1,2) (2,10)
        Lami compteurs)  (1,2) (2,9)
        tester ctt  (2,11) (2,45)
        tester ctt  (2,11) (2,45)
        ligne dans  (2,19) (2,40)
        le dans  (2,14) (2,40)
        ligne dans  (2,19) (2,40)
        le ligne  (2,14) (2,19)
        le dans  (2,14) (2,40)
        le ligne  (2,14) (2,19)
        vois? pour  (3,2) (2,38)
        vois? mot  (3,2) (2,15)
        vois? 2  (3,2) (2,8)
        vois? pour  (3,2) (2,38)
        mot pour  (2,15) (2,38)
        2 pour  (2,8) (2,38)
        vois? mot  (3,2) (2,15)
        mot pour  (2,15) (2,38)
        2 mot  (2,8) (2,15)
        vois? 2  (3,2) (2,8)
        2 pour  (2,8) (2,38)
        2 mot  (2,8) (2,15)
        


        1. C BON MERCI :)
        2. c'est à mon tour maintenannt de stocker ces nouveau nés :) (les mots joints ) dans la table de hachage seon la clé de hachage.
          merci
        3. Modérateur
          @stroumpfRe,

          je te conseille de créer une autre table de hash pour ça ;-)
        4. Modérateur
          @stroumpfJe te retourne la même question. Pourquoi dans la même? ;-)
      6. Modérateur
        ;-((( je ne vois pas

        En revanche on va faciliter un peu les choses.

        Sur ton texte je vais exécuter le programme (j'ai diminué la taille de la table")
        A toi de me montrer avec des exemple concrets les jointure que tu veuilles obtenir ;-))

        Le fichier
        lami20j@debian:~/trash$ cat fichier.txt
        Non Lami :)
        ben faut parcourir la table de hachage( 2 compteurs) , tester chaque avec le mot suivantselon la num ligne qui est enregistré dans la liste chaine(tu te souviens) et puis faire la jointure(calculer la clé de hachage pour stocker dans la table de hachage) ctt ;)
        tu vois?
        
        Le résultat
        lami20j@debian:~/trash$ ./posmot2
        Conteneur 0 :
                        ;)  (2,46)
                        clé  (2,35)
                        et  (2,29)
                        est  (2,21)
                        num  (2,18)
        -------------------------------------------------
        Conteneur 1 :
                        chaine(tu  (2,26)
        -------------------------------------------------
        Conteneur 2 :
                        stocker  (2,39)
        -------------------------------------------------
        Conteneur 3 :
                        liste  (2,25)
                        :)  (1,3)
                        Non  (1,1)
        -------------------------------------------------
        Conteneur 5 :
                        puis  (2,30)
                        enregistré  (2,22)
                        de  (2,43)  (2,36)  (2,6)
        -------------------------------------------------
        Conteneur 6 :
                        faire  (2,31)
                        qui  (2,20)
                        hachage(  (2,7)
        -------------------------------------------------
        Conteneur 7 :
                        tu  (3,1)
                        hachage)  (2,44)
                        avec  (2,13)
                        table  (2,42)  (2,5)
        -------------------------------------------------
        Conteneur 8 :
                        te  (2,27)
                        suivantselon  (2,16)
                        chaque  (2,12)
                        parcourir  (2,3)
        -------------------------------------------------
        Conteneur 9 :
                        faut  (2,2)
                        ben  (2,1)
        -------------------------------------------------
        Conteneur 10 :
                        hachage  (2,37)
                        souviens)  (2,28)
                        ,  (2,10)
                        compteurs)  (2,9)
                        Lami  (1,2)
        -------------------------------------------------
        Conteneur 11 :
                        la  (2,41)  (2,34)  (2,32)  (2,24)  (2,17)  (2,4)
        -------------------------------------------------
        Conteneur 12 :
                        jointure(calculer  (2,33)
        -------------------------------------------------
        Conteneur 13 :
                        ctt  (2,45)
                        tester  (2,11)
        -------------------------------------------------
        Conteneur 15 :
                        dans  (2,40)  (2,23)
                        ligne  (2,19)
                        le  (2,14)
        -------------------------------------------------
        Conteneur 16 :
                        vois?  (3,2)
                        pour  (2,38)
                        mot  (2,15)
                        2  (2,8)
        -------------------------------------------------
        Chercher mot : mot
        mot :  (2,15)
        1. ok :)
          Conteneur 0 :
          ;) (2,46)
          clé (2,35)
          et (2,29)
          est (2,21)
          num (2,18)
          exple au niveau de ce conteneur , il va y avoir des vointure pour caque couple de mot afin de produire de couple de mots , mais la jointure se fait entre les mots qui ont le meme num-ligne
          repone :
          clé;) (2,46)
          et;) (2,46)
          est;) (2,46)
          num;) (2,46)
          et clé (2,35)
          ets clé (2,35)
          num clé (2,35)

          .. aisi de suite
          il faut num position de second mot soit plus grand que le 1er mot :" est clé " et non pas "clé est"
          cbon?
      7. Modérateur
        Ce que tu veux obtenir n'a rien avoir avec la table mais avec le fichier.
        Dans la table les mot sont enregistrés suite à leur clé de hachage et pas en fonction de numéro de ligne.

        Ce que tu veux maintenant je trouve superflu puisqu'en fait la jointure que tu veux c'est le fichier lui même.

        Donc tu veux reconvertir la table hash dans le fichier qui existe déjà.

        1. Non Lami :)
          ben faut parcourir la table de hachage( 2 compteurs) , tester chaque avec le mot suivantselon la num ligne qui est enregistré dans la liste chaine(tu te souviens) et puis faire la jointure(calculer la clé de hachage pour stocker dans la table de hachage) ctt ;)
          tu vois?
      8. Modérateur
        Salut,

        je ne comprends pas
        en ce cas (1,3) c'est quoi pour "Bonjour toto"?
        si 1 c'est le numéro de ligne, alors 3 c'est quoi?

        Si tu donne une exemple concret

        par exemple dans la table tu as pour la clé (en supposant que aaa et bbb ont la même clé)

        aaa avec (1,2) (3,1)
        bbb avec (5,1) (10,1)

        Tu veux obtenir "aaa bbb" et ?????

        1. merci Lami de m'avoir repondu.
          supposons qu'on a le mot "bonjour" (1,3) ligne num 1 et position 3
          et le mot "Lami"(1,4) ligne num 1 et position 4
          donc la jointure ca sera "Bonjour LAmi"(1,4)

          sachant que la jointure se fait sssi entre deux mots qui ont le meme ligne num
          tu vois ?
        2. la "aaa"" et "bbb"" ne sejoint pas car il n'ont pas le meme num_ligne
      9. Bonjour a tous ;
        mon probleme consiste à developper une la fonction "jointure" qui permet de faire la jointure de tt les elements de la table de hachage( on joint les elemnt qui ont le meme num de ligne) pour produire elment joint (exp "BONJOUR TOTO") avec info (1,3)
        merci,
        1. Modérateur
          Salut,

          mais c mieux de faire un seul parcours du fichier
          J'ai créé une fonction (voir en gras) qui parcours le fichier, insère les mots dans la table de hash et traite aussi les position et le numéro de ligne ;-)

          Voilà, l'exemple complet

          table_hash.h
          /* table_hash.h */
          
          #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;
          }Liste;
          
          
          Liste *InsertionEnTete(Liste *L,char *mot);
          void InsertionTableHash(FILE *F, Liste **TableHash);
          Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
          void AfficherListe(Liste *L);
          void AfficherCoordonnees(Coordonnees *C);
          void AfficheMot(char *mot);
          void ParcourirElementTableHash(Liste **TableHash,char *mot);
          unsigned int hash_cle(char *mot);
          void AfficherTableHash(Liste **TableHash);
          unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
          void PosLigne(FILE *F,Liste **TableHash);
          
          #endif
          
          posmot2.c
          /* posmot2.c */
          #include<stdio.h>
          #include<stdlib.h>
          #include<string.h>
          #include<ctype.h>
          #include "table_hash.h"
          #define TAILLEHASH 307
          
          int main()
          {
            FILE *F;
            Liste **TableHash;
            char mot[100];
            int i;
          
            TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
            for(i=0;i<TAILLEHASH;++i)
              TableHash[i] = NULL;
          
            F=fopen("stroumpf.txt","r");
            InsertionTableHash(F,TableHash);
            fclose(F);
            AfficherTableHash(TableHash);
          
            printf("Chercher mot : ");
            scanf("%s",mot);
            if(ChercherMotDansTableHash(TableHash,mot))
              ParcourirElementTableHash(TableHash,mot);
            else
              printf("%s inexistant dans la table de hash\n");
            return 0;
          }
          
          Liste *InsertionEnTete(Liste *L,char *mot){
            Liste *nouveau;
            nouveau = (Liste *) malloc (sizeof(Liste));
            strcpy(nouveau->mot,mot);
            nouveau->suivant = L;
            nouveau->c = NULL;
            return nouveau;
          }
          
          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 AfficherListe(Liste *L){
            Liste *p;
            for(p=L;p!=NULL;p=p->suivant){
              AfficheMot(p->mot);
              AfficherCoordonnees(p->c);
            }
          }
          
          void AfficherCoordonnees(Coordonnees *C){
            Coordonnees *p;
            for(p=C;p!=NULL;p=p->suivant)
          	  printf(" (%d,%d) ",p->nl,p->pos);
            printf("\n");
          }
          
          void AfficheMot(char *mot){
            printf("%s ",mot);
          }
          
          unsigned int hash_cle(char *mot){
            unsigned int val = 0;
            for(;*mot!='\0';++mot)
              val = *mot + 31 * val;
            return val % TAILLEHASH;
          }
          
          void AfficherTableHash(Liste **TableHash){
            int i;
            for(i=0;i<TAILLEHASH;++i)
              if(TableHash[i] != NULL){
                AfficherListe(TableHash[i]);
              }
          }
          
          unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
            
            Liste *p;
            unsigned int cle;
            
            cle = hash_cle(mot);
            for(p=TableHash[cle];p!=NULL;p=p->suivant)
              if(strcmp(p->mot,mot)==0)
                return 1;
            return 0;
          }
          
          void InsertionTableHash(FILE *F, Liste **TableHash){
            int nl,pos,i;
            unsigned int cle;
            char mot[100];
            Liste *p;
            nl=pos=1;
            
            while(fscanf(F,"%s",mot)==1){
              cle = hash_cle(mot);
          
              if(! ChercherMotDansTableHash(TableHash,mot))
                TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
              for(p=TableHash[cle];p!=NULL;p=p->suivant){
                    if(strcmp(p->mot,mot)==0)
                      p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
              }
              if(fgetc(F)=='\n'){
                ++nl;
                pos=0;
              }
              ++pos;
            }
          }
          
          void ParcourirElementTableHash(Liste **TableHash,char *mot){
            int cle;
            Liste *p;
            cle = hash_cle(mot);
          
            for(p=TableHash[cle];p!=NULL;p=p->suivant)
              if(strcmp(mot,p->mot) == 0){
                printf("%s : ",mot);
                AfficherCoordonnees(p->c);
              }
          }
          
          Exécution
          lami20j@debian:~/trash$ gcc posmot2.c -o posmot2
          lami20j@debian:~/trash$ ./posmot2
          piu'  (13,2)
          troppa  (10,2)
          buongiorno  (17,1)  (15,1)
          amore  (11,5)
          sopra  (8,4)
          occhi  (16,3)
          sai  (18,2)
          chitarra  (2,3)
          sui  (10,4)
          al  (5,5)
          .  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)
          destra  (7,6)
          un  (8,2)  (6,2)  (4,2)
          partigiano  (6,3)
          cantare  (3,2)  (1,2)
          la  (8,5)  (2,2)
          suore  (13,6)
          le  (11,2)
          lo  (18,1)
          donne  (13,3)
          Lasciatemi  (1,1)
          tuoi  (9,5)
          e  (8,1)  (6,1)
          ci  (18,4)
          i  (9,4)
          mano  (7,5)
          Presidente.  (6,5)
          lasciatemi  (3,1)
          pieni  (16,4)
          sono  (18,5)  (4,1)
          di  (16,5)
          spaghetti  (5,4)
          malinconia  (16,6)
          con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
          Italia  (14,2)  (9,2)  (5,2)
          Buongiorno  (14,1)  (9,1)  (5,1)
          dente  (5,6)
          nella  (7,4)
          mano.  (2,5)
          finestra  (8,6)
          l'autoradio  (7,2)
          italiano  (4,3)
          come  (6,4)
          gli  (16,2)  (5,3)
          che  (18,3)
          canarino  (8,3)
          Dio  (17,2)
          cuore  (12,3)
          artisti.  (9,6)
          anch'io  (18,6)
          Maria  (15,2)
          canzoni  (11,3)
          sempre  (13,4)  (7,3)
          meno  (13,5)
          manifesti.  (10,5)
          America  (10,3)
          il  (12,2)
          in  (2,4)
          Chercher mot : con
          con :  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
          lami20j@debian:~/trash$ 


          1. Modérateur
            Je suis d'accord avec toi pour les 2 parcours.

            Une solution sera d'ajouter de champs dans la structure du mot 2 champs pour pos et ligne
            1. Bien, c fonctionnaant ;)
              mais c mieux de faire un seul parcours du fichier pour diminuer le coût CPU.
              1. Modérateur
                Salut,

                table_hash.h
                /* table_hash.h */
                
                #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;
                }Liste;
                
                
                Liste *InsertionEnTete(Liste *L,char *mot);
                Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
                void AfficherListe(Liste *L);
                void AfficherCoordonnees(Coordonnees *C);
                void AfficheMot(char *mot);
                void ParcourirElementTableHash(Liste **TableHash,char *mot);
                unsigned int hash_cle(char *mot);
                void AfficherTableHash(Liste **TableHash);
                unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
                void PosLigne(FILE *F,Liste **TableHash);
                
                #endif
                
                posmot.c
                /* posmot.c */
                #include<stdio.h>
                #include<stdlib.h>
                #include<string.h>
                #include<ctype.h>
                #include "table_hash.h"
                #define TAILLEHASH 307
                
                int main()
                {
                  FILE *F;
                  char mot[100];
                  int i;
                  unsigned int cle;
                  int nl, pos;
                  nl=pos=1;
                
                  Liste **TableHash;
                  TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
                  for(i=0;i<TAILLEHASH;++i)
                    TableHash[i] = NULL;
                
                  F=fopen("stroumpf.txt","r");
                
                  while(fscanf(F,"%s",mot)==1){
                    cle = hash_cle(mot);
                    if(! ChercherMotDansTableHash(TableHash,mot))
                      TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
                  }
                  fclose(F);
                  F=fopen("stroumpf.txt","r");
                  PosLigne(F,TableHash);
                  AfficherTableHash(TableHash);
                
                  printf("Chercher mot : ");
                  scanf("%s",mot);
                  if(cle = ChercherMotDansTableHash(TableHash,mot))
                    ParcourirElementTableHash(TableHash,mot);
                  else
                    printf("%s inexistant dans la table de hash\n");
                  return 0;
                }
                
                
                
                Liste *InsertionEnTete(Liste *L,char *mot){
                  Liste *nouveau;
                  nouveau = (Liste *) malloc (sizeof(Liste));
                  strcpy(nouveau->mot,mot);
                  nouveau->suivant = L;
                  nouveau->c = NULL;
                  return nouveau;
                }
                
                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 AfficherListe(Liste *L){
                  Liste *p;
                  for(p=L;p!=NULL;p=p->suivant){
                    AfficheMot(p->mot);
                    AfficherCoordonnees(p->c);
                  //  printf("\n");
                  }
                }
                
                void AfficherCoordonnees(Coordonnees *C){
                  Coordonnees *p;
                  for(p=C;p!=NULL;p=p->suivant)
                	  printf(" (%d,%d) ",p->nl,p->pos);
                  printf("\n");
                }
                
                void AfficheMot(char *mot){
                  printf("%s ",mot);
                }
                
                unsigned int hash_cle(char *mot){
                  unsigned int val = 0;
                  for(;*mot!='\0';++mot)
                    val = *mot + 31 * val;
                  return val % TAILLEHASH;
                }
                
                void AfficherTableHash(Liste **TableHash){
                  int i;
                  for(i=0;i<TAILLEHASH;++i)
                    if(TableHash[i] != NULL){
                  //    printf("Conteneur %d : ",i);
                      AfficherListe(TableHash[i]);
                  //    printf("-------------------------------------------------\n");
                    }
                }
                
                unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
                  
                  Liste *p;
                  unsigned int cle;
                  
                  cle = hash_cle(mot);
                  for(p=TableHash[cle];p!=NULL;p=p->suivant)
                    if(strcmp(p->mot,mot)==0)
                      return 1;
                  return 0;
                }
                
                
                
                void PosLigne(FILE *F,Liste **TableHash){
                  char s[50];
                  int nl,pos,i;
                  Liste *p;
                  nl=pos=1;
                
                  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)
                          if(strcmp(p->mot,s)==0)
                            p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
                    if(fgetc(F)=='\n'){
                      ++nl;
                      pos=0;
                    }
                    ++pos;
                  }
                  printf("\n");
                }
                
                void ParcourirElementTableHash(Liste **TableHash,char *mot){
                  int cle;
                  Liste *p;
                  cle = hash_cle(mot);
                
                  for(p=TableHash[cle];p!=NULL;p=p->suivant)
                    if(strcmp(mot,p->mot) == 0){
                      printf("%s : ",mot);
                      AfficherCoordonnees(p->c);
                    }
                }
                
                Exécution
                lami20j@debian:~/trash$ ./posmot
                
                piu'  (13,2)
                troppa  (10,2)
                buongiorno  (17,1)  (15,1)
                amore  (11,5)
                sopra  (8,4)
                occhi  (16,3)
                sai  (18,2)
                chitarra  (2,3)
                sui  (10,4)
                al  (5,5)
                .  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)
                destra  (7,6)
                un  (8,2)  (6,2)  (4,2)
                partigiano  (6,3)
                cantare  (3,2)  (1,2)
                la  (8,5)  (2,2)
                suore  (13,6)
                le  (11,2)
                lo  (18,1)
                donne  (13,3)
                Lasciatemi  (1,1)
                tuoi  (9,5)
                e  (8,1)  (6,1)
                ci  (18,4)
                i  (9,4)
                mano  (7,5)
                Presidente.  (6,5)
                lasciatemi  (3,1)
                pieni  (16,4)
                sono  (18,5)  (4,1)
                di  (16,5)
                spaghetti  (5,4)
                malinconia  (16,6)
                con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
                Italia  (14,2)  (9,2)  (5,2)
                Buongiorno  (14,1)  (9,1)  (5,1)
                dente  (5,6)
                nella  (7,4)
                mano.  (2,5)
                finestra  (8,6)
                l'autoradio  (7,2)
                italiano  (4,3)
                come  (6,4)
                gli  (16,2)  (5,3)
                che  (18,3)
                canarino  (8,3)
                Dio  (17,2)
                cuore  (12,3)
                artisti.  (9,6)
                anch'io  (18,6)
                Maria  (15,2)
                canzoni  (11,3)
                sempre  (13,4)  (7,3)
                meno  (13,5)
                manifesti.  (10,5)
                America  (10,3)
                il  (12,2)
                in  (2,4)
                Chercher mot : con
                con :  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
                lami20j@debian:~/trash$  
                Donc à la demande le mot de la table de hash est affiché ainsi que la liste chaînée qui lui correspond.
                1. Modérateur
                  Salut,

                  et ce ci est grave car il va y avoir un probleme de collision , non?
                  Exactement.
                  Ce n'est pas grave ça ;-)

                  Tu as plusieurs solutions solutions :
                  1. tu augmentes la taille de table de hachage

                  2. tu crées une fonctions de hachage meilleure

                  De toute façon les colissions ce n'est pas si grave puisqu'en fait au lieu d'avoir unel iste chaînée de n éléments tu auras plusieurs listes avec le nombre d'éléments égal avec le facteur de charge.

                  Une fonction de recherche d'un mot te permettra de trouver ce que tu as besoin.

                  Sinon, dans la fonction
                  void AfficherTableHash(Liste **TableHash){
                  int i;
                  for(i=0;i<TAILLEHASH;++i)
                  if(TableHash[i] != NULL){
                  printf("Conteneur %d : ",i);
                  AfficherListe(TableHash[i]);
                  printf("-------------------------------------------------\n");
                  }
                  }
                  tu la écris comme ça
                  void AfficherTableHash(Liste **TableHash){
                    int i;
                    for(i=0;i<TAILLEHASH;++i)
                      if(TableHash[i] != NULL){
                        AfficherListe(TableHash[i]);
                        printf("-------------------------------------------------\n");
                      }
                  }
                  
                  et tu ne te rendra même pas compte qu'il y a des collisions ;-))
                  De toute façon, avoir une table de hachage sans collision c'est l'idéal (donc une utopie ;-)

                  1. Ok merci Lami,
                    Ben moi je traite un gros gros corpus texte ( contenant plus 100 000) phrase: ;)
                    comme ca il va pas yavoir des collision.
                    ?
                  2. Rebonsoir LAmi, bon voila la fonction fréquent: ba normallement elle fonction pour elliminer les bruits, sauf elle n'ellimine pas les element de la table de hachage
                    ta une idee svp?

                    void frequent( Liste **L , int mc)
                    {
                         Liste *m=*L;
                         Liste* prev=*L;
                         Coordonnees* C=NULL;
                         int sup, lig=0;
                         while(m!=NULL) 
                         {
                             C=m->c;
                             sup=0;
                             lig=0;
                             while (C!=NULL)     
                             {
                                   if (C->nl > lig)
                                   {
                                       sup++;
                                       lig= C->nl;                                   
                                   }
                                   C=C->suivant;
                             } 
                             if (sup>mc) 
                             {
                                prev=m;         
                                m=m->suivant;
                                // c bon          
                             }else
                             {
                                  if (prev==m) // cas du première mot
                                     {
                                        *L=m->suivant;
                                        prev=m->suivant;
                                     }
                                  else
                                     prev->suivant=m->suivant;
                                m=m->suivant;
                              // on supprime le mot    
                             }                 
                         }
                    }
                2. Modérateur
                  Il reste juste l passage avec frequent à traiter
                  table_hash.h
                  /* table_hash.h */
                  
                  #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;
                  }Liste;
                  
                  
                  Liste *InsertionEnTete(Liste *L,char *mot);
                  Coordonnees *InsertionEnTeteCoordonnee(Coordonnees *C,int nl,int pos);
                  void AfficherListe(Liste *L);
                  void AfficherCoordonnees(Coordonnees *C);
                  void AfficheMot(char *mot);
                  unsigned int hash_cle(char *mot);
                  void AfficherTableHash(Liste **TableHash);
                  unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot);
                  void PosLigne(FILE *F,Liste **TableHash);
                  
                  #endif
                  

                  posmot.c
                  /* posmot.c */
                  #include<stdio.h>
                  #include<stdlib.h>
                  #include<string.h>
                  #include<ctype.h>
                  #include "table_hash.h"
                  #define TAILLEHASH 307
                  
                  int main()
                  {
                    FILE *F;
                    char mot[100];
                    int i;
                    unsigned int cle;
                    int nl, pos;
                    nl=pos=1;
                  
                    Liste **TableHash;
                    TableHash = (Liste **) malloc (TAILLEHASH * sizeof(Liste *));
                    for(i=0;i<TAILLEHASH;++i)
                      TableHash[i] = NULL;
                  
                    F=fopen("stroumpf.txt","r");
                  
                    while(fscanf(F,"%s",mot)==1){
                      cle = hash_cle(mot);
                      if(! ChercherMotDansTableHash(TableHash,mot))
                        TableHash[cle] = InsertionEnTete(TableHash[cle],mot);
                    }
                    fclose(F);
                    F=fopen("stroumpf.txt","r");
                    PosLigne(F,TableHash);
                    AfficherTableHash(TableHash);
                  
                    //printf("Chercher mot : ");
                    //scanf("%s",mot);
                    //if(cle = ChercherMotDansTableHash(TableHash,mot))
                    //  printf("%s existant dans le conteneur %u\n",mot,hash_cle(mot));
                    //else
                    //  printf("%s inexistant dans la table de hash\n");
                    return 0;
                  }
                  
                  
                  
                  Liste *InsertionEnTete(Liste *L,char *mot){
                    Liste *nouveau;
                    nouveau = (Liste *) malloc (sizeof(Liste));
                    strcpy(nouveau->mot,mot);
                    nouveau->suivant = L;
                    nouveau->c = NULL;
                    return nouveau;
                  }
                  
                  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 AfficherListe(Liste *L){
                    Liste *p;
                    for(p=L;p!=NULL;p=p->suivant){
                      AfficheMot(p->mot);
                      AfficherCoordonnees(p->c);
                      printf("\n");
                    }
                  }
                  
                  void AfficherCoordonnees(Coordonnees *C){
                    Coordonnees *p;
                    for(p=C;p!=NULL;p=p->suivant)
                  	  printf(" (%d,%d) ",p->nl,p->pos);
                    printf("\n");
                  }
                  
                  void AfficheMot(char *mot){
                    printf("%s ",mot);
                  }
                  
                  unsigned int hash_cle(char *mot){
                    unsigned int val = 0;
                    for(;*mot!='\0';++mot)
                      val = *mot + 31 * val;
                    return val % TAILLEHASH;
                  }
                  
                  void AfficherTableHash(Liste **TableHash){
                    int i;
                    for(i=0;i<TAILLEHASH;++i)
                      if(TableHash[i] != NULL){
                        printf("Conteneur %d : ",i);
                        AfficherListe(TableHash[i]);
                        printf("-------------------------------------------------\n");
                      }
                  }
                  
                  unsigned int ChercherMotDansTableHash(Liste **TableHash,char *mot){
                    
                    Liste *p;
                    unsigned int cle;
                    
                    cle = hash_cle(mot);
                    for(p=TableHash[cle];p!=NULL;p=p->suivant)
                      if(strcmp(p->mot,mot)==0)
                        return 1;
                    return 0;
                  }
                  
                  
                  
                  void PosLigne(FILE *F,Liste **TableHash){
                    char s[50];
                    int nl,pos,i;
                    Liste *p;
                    nl=pos=1;
                  
                    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)
                            if(strcmp(p->mot,s)==0)
                              p->c=InsertionEnTeteCoordonnee(p->c,nl ,pos);
                      if(fgetc(F)=='\n'){
                        ++nl;
                        pos=0;
                      }
                      ++pos;
                    }
                    printf("\n");
                  }
                  
                  
                  


                  Test sur
                  Lasciatemi cantare .
                  con la chitarra in mano.
                  lasciatemi cantare .
                  sono un italiano .
                  Buongiorno Italia gli spaghetti al dente .
                  e un partigiano come Presidente.
                  con l'autoradio sempre nella mano destra .
                  e un canarino sopra la finestra .
                  Buongiorno Italia con i tuoi artisti.
                  con troppa America sui manifesti.
                  con le canzoni con amore .
                  con il cuore .
                  con piu' donne sempre meno suore .
                  Buongiorno Italia .
                  buongiorno Maria .
                  con gli occhi pieni di malinconia .
                  buongiorno Dio .
                  lo sai che ci sono anch'io .


                  lami20j@debian:~/trash$ ./a.out
                  
                  Conteneur 0 : piu'  (13,2)
                  
                  -------------------------------------------------
                  Conteneur 19 : troppa  (10,2)
                  
                  -------------------------------------------------
                  Conteneur 22 : buongiorno  (17,1)  (15,1)
                  
                  -------------------------------------------------
                  Conteneur 31 : amore  (11,5)
                  
                  -------------------------------------------------
                  Conteneur 33 : sopra  (8,4)
                  
                  -------------------------------------------------
                  Conteneur 35 : occhi  (16,3)
                  
                  -------------------------------------------------
                  Conteneur 37 : sai  (18,2)
                  
                  -------------------------------------------------
                  Conteneur 40 : chitarra  (2,3)
                  
                  -------------------------------------------------
                  Conteneur 43 : sui  (10,4)
                  
                  -------------------------------------------------
                  Conteneur 45 : al  (5,5)
                  
                  -------------------------------------------------
                  Conteneur 46 : .  (18,7)  (17,3)  (16,7)  (15,3)  (14,3)  (13,7)  (12,4)  (11,6)  (8,7)  (7,7)  (5,7)  (4,4)  (3,3)  (1,3)
                  
                  -------------------------------------------------
                  Conteneur 53 : destra  (7,6)
                  
                  un  (8,2)  (6,2)  (4,2)
                  
                  -------------------------------------------------
                  Conteneur 58 : partigiano  (6,3)
                  
                  -------------------------------------------------
                  Conteneur 64 : cantare  (3,2)  (1,2)
                  
                  -------------------------------------------------
                  Conteneur 68 : la  (8,5)  (2,2)
                  
                  -------------------------------------------------
                  Conteneur 69 : suore  (13,6)
                  
                  -------------------------------------------------
                  Conteneur 72 : le  (11,2)
                  
                  -------------------------------------------------
                  Conteneur 82 : lo  (18,1)
                  
                  -------------------------------------------------
                  Conteneur 86 : donne  (13,3)
                  
                  -------------------------------------------------
                  Conteneur 92 : Lasciatemi  (1,1)
                  
                  -------------------------------------------------
                  Conteneur 101 : tuoi  (9,5)
                  
                  e  (8,1)  (6,1)
                  
                  -------------------------------------------------
                  Conteneur 104 : ci  (18,4)
                  
                  -------------------------------------------------
                  Conteneur 105 : i  (9,4)
                  
                  -------------------------------------------------
                  Conteneur 113 : mano  (7,5)
                  
                  -------------------------------------------------
                  Conteneur 122 : Presidente.  (6,5)
                  
                  -------------------------------------------------
                  Conteneur 125 : lasciatemi  (3,1)
                  
                  -------------------------------------------------
                  Conteneur 131 : pieni  (16,4)
                  
                  sono  (18,5)  (4,1)
                  
                  -------------------------------------------------
                  Conteneur 135 : di  (16,5)
                  
                  spaghetti  (5,4)
                  
                  -------------------------------------------------
                  Conteneur 136 : malinconia  (16,6)
                  
                  -------------------------------------------------
                  Conteneur 143 : con  (16,1)  (13,1)  (12,1)  (11,4)  (11,1)  (10,1)  (9,3)  (7,1)  (2,1)
                  
                  -------------------------------------------------
                  Conteneur 147 : Italia  (14,2)  (9,2)  (5,2)
                  
                  Buongiorno  (14,1)  (9,1)  (5,1)
                  
                  -------------------------------------------------
                  Conteneur 152 : dente  (5,6)
                  
                  -------------------------------------------------
                  Conteneur 163 : nella  (7,4)
                  
                  -------------------------------------------------
                  Conteneur 172 : mano.  (2,5)
                  
                  -------------------------------------------------
                  Conteneur 186 : finestra  (8,6)
                  
                  -------------------------------------------------
                  Conteneur 193 : l'autoradio  (7,2)
                  
                  -------------------------------------------------
                  Conteneur 197 : italiano  (4,3)
                  
                  -------------------------------------------------
                  Conteneur 205 : come  (6,4)
                  
                  gli  (16,2)  (5,3)
                  
                  -------------------------------------------------
                  Conteneur 224 : che  (18,3)
                  
                  -------------------------------------------------
                  Conteneur 229 : canarino  (8,3)
                  
                  -------------------------------------------------
                  Conteneur 253 : Dio  (17,2)
                  
                  -------------------------------------------------
                  Conteneur 257 : cuore  (12,3)
                  
                  artisti.  (9,6)
                  
                  -------------------------------------------------
                  Conteneur 261 : anch'io  (18,6)
                  
                  -------------------------------------------------
                  Conteneur 266 : Maria  (15,2)
                  
                  -------------------------------------------------
                  Conteneur 269 : canzoni  (11,3)
                  
                  -------------------------------------------------
                  Conteneur 271 : sempre  (13,4)  (7,3)
                  
                  -------------------------------------------------
                  Conteneur 273 : meno  (13,5)
                  
                  -------------------------------------------------
                  Conteneur 277 : manifesti.  (10,5)
                  
                  -------------------------------------------------
                  Conteneur 292 : America  (10,3)
                  
                  -------------------------------------------------
                  Conteneur 293 : il  (12,2)
                  
                  -------------------------------------------------
                  Conteneur 295 : in  (2,4)
                  
                  -------------------------------------------------
                  lami20j@debian:~/trash$
                  
                  1. Merci Lami, mais le probleme ici reste qu'il ya des conteneurs quii contiennent plus qu'un mot, et ce ci est grave car il va y avoir un probleme de collision , non?
                • 1
                • 2