Skip to content

Instantly share code, notes, and snippets.

@cbergau
Created December 13, 2016 22:16
Show Gist options
  • Save cbergau/40715a730d62757ce0d6d22417811906 to your computer and use it in GitHub Desktop.
Save cbergau/40715a730d62757ce0d6d22417811906 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <windows.h>
int cmpfunc(const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int cstring_cmp(const void * a, const void * b) {
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
int main() {
int values[] = { 22, 23, 454, 1, 2, 3};
qsort(values, 6, sizeof(int), cmpfunc);
char *strings[] = { "Zorro", "Alex", "Celine", "Bill", "Forest", "Dexter" };
qsort(strings, sizeof(strings) / sizeof(char *), sizeof(char *), cstring_cmp);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment