Need4Sleep

Qsort Char** title

Nov 28th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int sort(const void* a, const void* b)
  5. {
  6. const char *ia = *(const char**)a;
  7. const char *ib = *(const char**)b;
  8. return strcmp(ia + 2,ib + 2);
  9. }
  10.  
  11. int main()
  12. {
  13.  
  14. char *ArrayFinal[4] =
  15. {
  16. {"2 -4 THIS IS LINE ONE"},
  17. {"1 -3 THIS IS LINE TWO"},
  18. {"6 -8 THIS IS LINE THREE"},
  19. {"3 -2 THIS IS LINE FOUR"}
  20. };
  21. qsort(ArrayFinal, (size_t)4, sizeof(char *), sort);
  22. int i;
  23. for(i = 0; i < 4; i++)
  24. printf("%s \n", ArrayFinal[i]);
  25. printf("Hello!");
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment