Bonjour
Je voudrais que mon programme puisse ajouter des mots grace a l'allocation dynamique, et a la linked list.
Je ne sais pas trop comment afficher les elements de la liste correctement de facon a ce que soit une liste numerotee
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 # include <stdio.h> # include <string.h> # include <stdlib.h> struct list { char word [ 50 ]; int ele; struct list * next; //struct list * prior; }; void Printlist (struct list *); int main ( void ) { int choice; struct list *start; start = (struct list *) malloc (sizeof (struct list)); start->ele = 1; do { printf("\n\n\t 1. Add a word"); printf("\n\t 2. Delete a word"); printf("\n\t 3. Search for and display"); printf("\n\t 4. Display data in queue order"); printf("\n\t 5. Quit"); printf("\n\n\t Enter your choice : "); scanf("%i", & choice); start->next = (struct list *) malloc (sizeof(struct list)); if ( choice == 1 ) { printf("\n\tEnter the word to add : "); scanf("%s", start->word); } if ( choice == 3 ) { Printlist ( start ); } } while ( choice != 5 ); return 0; } void Printlist (struct list * x) { while ( x != NULL ) { printf ("Element %i is : %s \n", x->ele, x->word); x = x->next; } }
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 element 1 is mot element 2 is mot2 element 2 is mot3 ...
Partager