Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *sources[] = {"this", "is", "a", "program", "for", "testing"};
  6.  
  7.  
  8. void printarray (char **stringarray, int length)
  9. {
  10.     int i = 0;
  11.     for (i; i < length; i++)
  12.     {
  13.         printf("%s ",stringarray[i]);
  14.     }
  15.     printf("\n");
  16.    
  17. }
  18.  
  19. int compare (const void *element1, const void *element2)
  20. {
  21.     return strcmp(*(const char**)element1,*(const char **)element2);
  22. }
  23.  
  24. int main (int argc, const char * argv[])
  25. {
  26.     printarray(sources,6);
  27.     qsort(sources, 6, sizeof(char *), compare);
  28.     printarray(sources,6);
  29.         return 0;
  30. }