bonjour

j essaye avec ce code de trier des mot dans une chaine separe par des espaces

exemple:

il fait beau
beau fait il
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> 
 
#define NBRMOTS 3 
#define LGMOT 20 
 
void tri_chaine_caract(char tableau[],int tabLength, int wordLength); 
 
main() 
{ 
   char tab[NBRMOTS][LGMOT]; 
   int i; 
   char choix; 
 
   printf("encodez une série de 3 mots! \n"); 
 
   for(i=0;i<NBRMOTS;i++) 
   { 
      printf("Mot %d : ", i); 
      scanf("%s", tab[i]); 
   } 
   do 
   { 
      printf("appuyez sur 'r' pour effectuer le tri \n"); 
      printf("appuyez sur 'q' pour quitter \n\n"); 
      choix=getch(); 
      if(choix=='q') 
      abort(); 
      else if(choix=='r') 
      { 
         tri_chaine_caract(tab,NBRMOTS,LGMOT); 
      } 
   } 
   while(choix!='q' && choix!='r'); 
} 
 
void tri_chaine_caract(char tableau[],int tabLength, int wordLength) 
{ 
   int i,k; 
   char temp[wordLength]; 
 
   for(i=0;i<tabLength;i++) 
   { 
      k=i; 
      while((k>=0) || (strcmp(tableau[k],tableau[k-1]<0))) 
      { 
         temp=tableau[k]; 
         tableau[k]=tableau[k-1]; 
         tableau[k-1]=temp; 
         k=k-1; 
      } 
   } 
}