fork download
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. int cmp(const void *a, const void *b){
  6. return strcmp(*(char**)b, *(char**)a);
  7. }
  8. void sort_words(char *words[], int count) {
  9. qsort(words, count, sizeof(*words), cmp);
  10. }
  11.  
  12. #ifndef RunTests
  13. int main()
  14. {
  15. char *words[] = { "cherry", "orange", "apple" };
  16.  
  17. sort_words(words, 3);
  18.  
  19. for (int i = 0; i < 3; i++)
  20. {
  21. printf("%s ", words[i]);
  22. }
  23. }
  24. #endif
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
orange cherry apple