Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     //ressources
  8.     int i,j;
  9.     char *chaine[10];
  10.     char buffer[500];
  11.     int *tmp;
  12.     int res;
  13.  
  14.     // On récupère 10 chaines de caractères.
  15.     for (i=0; i<10; i++){
  16.         fflush(stdin);
  17.         gets(buffer);
  18.         chaine[i] = (char *)malloc(strlen(buffer+1));
  19.         strcpy(chaine[i],buffer);
  20.     }
  21.  
  22.     // On tri nos 10 chaines
  23.     for (i = 0; i<10; i++)
  24.     {
  25.         for (j=0;j<9;j++)
  26.         {
  27.             res = strcmp(chaine[j],chaine[j+1]);
  28.                 if(res>0)
  29.                 {
  30.                 tmp = chaine[j];
  31.                 chaine[j] = chaine [j+1];
  32.                 chaine[j+1] = tmp;
  33.                 }
  34.         }
  35.     }
  36.  
  37.     // Affichage tableau trié
  38.     for(i=0;i<10;i++)
  39.         printf("%s\n",chaine[i]);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement