bonjour,
je cherche a trier une liste de nombres. Voici comment je fait :
et voila le main
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 void my_swap(int *a, int *b); int tribul(int * nbr) { int flags; int i; int j; i = 0; j = 1; while (flags == 0) { flags = 1; i = 0; while (nbr[i] != '\a') { flags = 1; if (nbr[i] > nbr[i + 1]) { puts("toto"); my_swap(&nbr[i], &nbr[i + 1]); flags = 0; } i++; } } return (0); } void my_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; }
Auriez vous une idée de pourquoi cela ne fonctionne pas ?
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 void my_putstr(char *str); int my_strlen(char *str); int my_get_nbr(char *str); int main(int ac , char **av) { int i; int j; int k; int *nbr; i = 0; j = 1; if (ac < 2) { return (1); my_putstr("sorry but you h<gras><italique><souligne>q</souligne></italique></gras>ve dont enter a good number of arguments"); } nbr = malloc(sizeof(*nbr) * ac); while (j < ac) { nbr[i] = my_get_nbr(av[j]); j++; i++; } nbr[i + 1] = 'a'; tribul(nbr); printf("%i", nbr[0]); printf("%i", nbr[2]); printf("%i", nbr[2]); printf("%i", nbr[4]); free(nbr); return (0); }
Partager