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
| #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 maliste = NULL;
char mot[80];
int main(int argc, char **argv)
{
printf("Please, enter a word: \n");
fgets(mot,80,stdin);
printf("You entered the word : %s \n",mot);
ajouterEnTete(maliste,mot);
afficherListe(maliste);
system("PAUSE");
return 0;
}
llist ajouterEnTete (llist liste, char const *mot){
element* nouvelElement = malloc(sizeof(element));
//nouvelElement->chaine = mot;
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;
printf("%s ", tmp->chaine);
printf("%d ", tmp->val);
while(tmp != NULL){
printf("affich");
printf("%s ", tmp->chaine);
printf("%d ", tmp->val);
tmp = tmp->nxt;
}
} |
Partager