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
   |  
#include <stdio.h>
#include <stdlib.h>
 
 
typedef struct element element;
struct element
{
    char chaine[80];
    int val;
    struct element *nxt;
};
typedef element* llist;
 
 
llist ajouterEnTete (llist liste, char const *mot);
void afficherListe(llist liste);
llist rechercherElement(llist liste, char const *mot);
 
 
char mot[80]; 
 
 
int main(int argc, char **argv)
{
llist maliste = NULL;
element* essai = malloc(sizeof(element));
beginning :
printf("Please, enter a word: \n");
fgets(mot,80,stdin);
printf("You entered the word : %s \n",mot);
essai=rechercherElement(maliste,mot);
//if(essai!=NULL){
//essai->val++;
//maliste=essai;
//}
//else{
maliste = ajouterEnTete(maliste,mot);
//}
printf("\n Type q to quit or Enter to continue \n");
char answer = getchar();
if(answer!='q'){
	goto beginning;
} 
 
 
afficherListe(maliste);
//printf("%s ", maliste->chaine);
//printf("%d ", maliste->val);
 
 system("PAUSE");
    return 0;
}
 
 
 
llist ajouterEnTete (llist liste, char const *mot){
element* nouvelElement = malloc(sizeof(element));
strcpy(nouvelElement->chaine,mot);
nouvelElement->val = 1;
//printf("jouter");
//printf("%s ", nouvelElement->chaine);
//printf("%d ", nouvelElement->val);
nouvelElement->nxt = liste;
return nouvelElement;
}
 
 
void afficherListe(llist liste){
    element *tmp = liste;
    int i=0,MAX=1;
     // while(tmp != NULL){
 
     // }
    //printf("%s ", tmp->chaine);
      //  printf("%d ", tmp->val);
      //while(i<=10){
    while(tmp != NULL){
        //printf("affich");
        printf("%s ", tmp->chaine);
        printf("%d ", tmp->val);
        tmp = tmp->nxt;
//}
 
    //tmp=liste;
}
 
llist rechercherElement(llist liste, char const *mot){
element *tmp=liste;
while(tmp != NULL){
if(!strcasecmp(tmp->chaine,mot)){
	printf("Word spellt correctly");
       return tmp;
       }
   tmp = tmp->nxt;
   }
   return NULL;
}
} | 
Partager