Last active
May 17, 2018 03:08
-
-
Save michaeljdennis/ee36614cc7bc81f63aa08bbcc51a4234 to your computer and use it in GitHub Desktop.
Sort Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
static int myCompare (const void * a, const void * b) | |
{ | |
return strcmp (*(const char **) a, *(const char **) b); | |
} | |
void sort(const char *arr[], int n) | |
{ | |
qsort (arr, n, sizeof (const char *), myCompare); | |
} | |
int main () | |
{ | |
const char *arr[] = { | |
"john", | |
"bobby", | |
"dear", | |
"test1", | |
"catherine", | |
"nomi", | |
"shinta", | |
"martin", | |
"abe", | |
"may", | |
"zeno", | |
"zack", | |
"angeal", | |
"gabby" | |
}; | |
int n = sizeof(arr)/sizeof(arr[0]); | |
int i; | |
sort(arr, n); | |
for (i = 0; i < n; i++) { | |
printf("%d: %s \n", i, arr[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment