Bonsoir,

j'ai codé ce bout de programme pour trier par ordre ascii une liste de chaine de caractère qu'on rentre en paramètre.
Ce que je pensais c'etait parser, reparser, rereparser... mon char ** tant que tous les strcmp sont > 0
est ce que quelqu'un pourrait m'aiguiller un peu?

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
void    swap(char **s1, char **s2)
{
  char  *tmp;
 
  tmp = *s1;
  *s1 = *s2;
  *s2 = tmp;
}
 
int     main(int ac, char **av)
{
  int   i;
  int   en_bordel;
  int   check;
 
  en_bordel = 1;
  while (en_bordel == 1)
    {
      i = 1;
      en_bordel = 0;
      while (i < ac)
        {
          if (av[i+1] == '\0')
            i = 1;
          else
            printf("[%d]\n", strcmp(av[i], av[i+1]));
          printf("Avant: av[i]: %s\n", av[i]);
          printf("Avant: av[i+1]: %s\n", av[i+1]);
          if (strcmp(av[i], av[i+1]) > 0)
            {
              swap(&av[i], &av[i+1]);
              en_bordel = 1;
            }
          printf("Apres: av[i]: %s\n", av[i]);
          printf("Apres: av[i+1]: %s\n", av[i+1]);
          i++;
        }
     }
  return (0);
}