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
|
/* ajoute word dans la table */
void hash_table_add(char *word) {
e.key = word;
/*
* Test si le mot n'est pas dans notre HashTable
* auquel cas on le rajoute
*/
if((ep = hsearch(e, FIND)) == NULL) {
/* e.data est un int
* permet d'associer la key de manière unique
*/
printf("%s\n",e.key);
e.data = (void *) 1;
ep = hsearch(e, ENTER);
/* there should be no failures */
if (ep == NULL) {
fprintf(stderr, "entry failed\n");
exit(EXIT_FAILURE);
}
} else { // sinon on incrémente son data de 1
ep = hsearch(e, FIND);
/*int data = (int) ep->data + 1;
ep->data = (void*) data;*/
ep->data += 1;
hsearch(*ep,ENTER);
}
} |
Partager