fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<time.h>
  5.  
  6. void sort(char** tab, int size)
  7. {
  8. char* temp = (char*)malloc(99);
  9. int i, j;
  10.  
  11. for(i = 0; i < size; ++i)
  12. {
  13. for(j = 0; j < size-1-i; ++j)
  14. {
  15. if(strcmp(tab[j], tab[j+1]) > 0)
  16. strcpy(temp, tab[j]),
  17. strcpy(tab[j], tab[j+1]),
  18. strcpy(tab[j+1], temp);
  19. }
  20. }
  21. for(i = 0; i < size; ++i)
  22. puts(tab[i]);
  23. }
  24.  
  25. int main()
  26. {
  27. srand(time(NULL));
  28. int size = rand()%5+5, i, j, s;
  29. char** tab = (char**)malloc(size * sizeof(char*));
  30.  
  31. for(i = 0; i < size; ++i)
  32. {
  33. s = rand()%9+1;
  34. tab[i] = (char*)malloc(s+1);
  35. for(j = 0; j < s; ++j)
  36. tab[i][j] = 'a'+rand()%26;
  37. tab[i][s] = 0;
  38. }
  39. for(i = 0; i < size; ++i)
  40. puts(tab[i]);
  41. puts("");
  42. sort(tab, size);
  43. return 0;
  44. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
ql
w
k
oobhighcb
rob
jqjpyq
jwgbje

jqjpyq
jwgbje
k
oobhighcb
ql
rob
w