Skip to content

Instantly share code, notes, and snippets.

@cbergau cbergau/qsort.c
Created Dec 13, 2016

Embed
What would you like to do?
#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
You can’t perform that action at this time.