Donc voila je cherche a faire une liste chainée toute simple...Et il me met incompatible pointer type pour toutes les fonctions que j'ai crée. Je passe bien en argumente un pointeur sur une liste...Mais il trouve ca incorrect...Si quelqu'un pouvait m'aider...Merci.
(J'ai un second probleme, quand je fais tourner le programme avec ces warnings, au bout de 4 enregistrements ca plante...Donc surement un probleme dans le malloc ?)
Erreur :
main.c:12: warning: passing arg 1 of `initialize' from incompatible pointer type
main.c:12: warning: passing arg 2 of `initialize' from incompatible pointer type
main.c:25: warning: passing arg 1 of `newElements' from incompatible pointer type
main.c:38: warning: passing arg 1 of `addElements' from incompatible pointer type
main.c:38: warning: passing arg 2 of `addElements' from incompatible pointer type
main.c:48: warning: passing arg 1 of `printChain' from incompatible pointer type
ChainFunction.c
ChainHeader.h
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
51
52
53
54
55
56
57
58 #include <stdio.h> #include <stdlib.h> #include "ChainHeader.h" //initialize begin and end list int initialize (list * f_listBegin, list * f_listEnd) { f_listBegin = NULL; f_listEnd = NULL; return 0; } //Create new Elements and initialize it int newElements (list * f_listNew, float f_val) { f_listNew = (list *) malloc(sizeof(list *)); f_listNew->val = f_val; f_listNew->ChainListNext = NULL; f_listNew->ChainListBefore = NULL; return 0; } //add elements int addElements (list * f_listNew, list * f_listEnd) { f_listEnd -> ChainListNext = f_listNew; f_listNew -> ChainListBefore = f_listEnd; f_listEnd = f_listNew; return 0; } //Print Chain int printChain(list * f_listBegin) { list * listCurrent; listCurrent = f_listBegin; //NULL is the end of the List while(listCurrent != NULL) { printf("%d", listCurrent->val); listCurrent = listCurrent->ChainListNext; } return 0; }
Main.c
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 //Create a New Struct typedef struct ChainList { struct ChainList * ChainListNext; float val; struct ChainList * ChainListBefore; } list; list * listBegin, * listEnd, * listNew; int initialize (list * f_listBegin, list * f_listEnd); int newElements (list * f_listNew, float f_val); int addElements (list * f_listNew, struct ChainList * f_listEnd); int printChain(list * f_listBegin);
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
51
52
53 #include <stdio.h> #include <stdlib.h> #include "ChainHeader.h" int main(int argc, char ** argv) { //initialize var float nb = 0; //Initialize Begin and End initialize(&listBegin, &listEnd); printf("Enter a list of val :\n"); //Ask val while(nb != -1) { //Ask var scanf("%f", &nb); if(nb != -1) { //create new elements newElements(&listNew, nb); //If this is the first element in the chainlist if(listBegin == NULL) { listBegin = listNew; listEnd = listNew; } //If it isn't the first element in the chainlist else { addElements (&listNew, &listEnd); } } } //Print boucle printChain(&listBegin); //End of ChainList return 0; }
Partager