fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4. #include<unistd.h>
  5. #define NR 10
  6.  
  7. int cstring_cmp(const void *a, const void *b)
  8. {
  9. const char **ia = (const char **)a;
  10. const char **ib = (const char **)b;
  11. return strcmp(*ia, *ib);
  12. }
  13.  
  14. int main(void)
  15. {
  16. int i,k;
  17. char temp[1000];
  18. char* words_array[NR];
  19. for (i=0; i<NR; i++)
  20. {
  21. scanf("%s\n", temp);
  22. words_array[i] = (char*)malloc((strlen(temp) + 1)*sizeof(char));
  23. strcpy(words_array[i], temp);
  24.  
  25. }
  26.  
  27. qsort(words_array,NR ,sizeof(char *) ,cstring_cmp );
  28. printf ("\n");
  29. printf ("the sorted array list is:\n");
  30. for (i=0;i<NR;i++)
  31. {
  32. printf("%s\n", words_array [i]);
  33. }
  34. }
Runtime error #stdin #stdout 0s 2384KB
stdin
9
7
5
3
1
8
6
4
2
0
stdout
the sorted array list is:
0
1
2
3
4
5
6
7
8
9