So I've been trying to implement a generic quick sort for educational purposes and so far my quick sort has been able able to sort any array of integers just fine but it does not work with an array of strings. My only guess is that maybe I'm not offsetting the correct amount of bytes since I'm dealing with void pointers

Code

Code:#include <stdio.h> #include <stdlib.h> #include <string.h> void quickSort(void *, size_t, size_t, int (*cmp)(const void *, const void *)); void quickSort_r(void *, int, int, size_t, int (*cmp)(const void *, const void *)); int qSortPartition(void *, int, int, size_t, int (*cmp)(const void *, const void *)); int is_sorted(void *, size_t, size_t, int (*cmp)(const void *, const void *)); int cmp(const void *, const void *); void Swap(void *, void *, size_t); int main() { unsigned int i; char *a[] = {"Luis", "Daniel", "Alfredo", "Salvador", "Bruno"}; size_t numberOfElements = sizeof(a)/sizeof(a[0]); if(numberOfElements > 1) { quickSort(a, numberOfElements, sizeof(char *), cmp); } for(i = 0; i < numberOfElements; i++) { printf("%s ", a[i]); } return 0; } void quickSort(void *base, size_t nitems, size_t memSize, int (*cmp)(const void *, const void *)) { quickSort_r(base, 0, nitems - 1, memSize, cmp); } void quickSort_r(void *base, int first, int last, size_t memSize, int (*cmp)(const void *, const void *)) { if(first < last) { int pivot; if(is_sorted(base, last + 1, memSize, cmp)) { return ; } pivot = qSortPartition(base, first, last, memSize, cmp); quickSort_r(base, first, pivot - 1, memSize, cmp); quickSort_r(base, pivot + 1, last, memSize, cmp); } } int qSortPartition(void *base, int first, int last, size_t memSize, int (*cmp)(const void *, const void *)) { char *carray = (char *)base; int pivot, mid = (first + last) / 2; pivot = cmp(&carray[first * memSize], &carray[mid * memSize]) >= 1 ? first : mid; if(cmp(&carray[pivot * memSize], &carray[last * memSize]) >= 1) { pivot = last; } Swap(&carray[pivot * memSize], &carray[first * memSize], memSize); pivot = first; while(first < last) { if(cmp(&carray[first * memSize], &carray[last * memSize]) <= 0) { Swap(&carray[pivot * memSize], &carray[first * memSize], memSize); pivot++; } first++; } Swap(&carray[pivot * memSize], &carray[last * memSize], memSize); return pivot; } int is_sorted(void *base, size_t nitems, size_t memSize, int (*cmp)(const void *, const void *)) { char *carray = (char *)base; unsigned int i; for(i = 0; i < nitems - 1; i++) { if(cmp(&carray[i * memSize], &carray[i + 1 * memSize]) >= 1) { return 0; } } return 1; } int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); } void Swap(void *a, void *b, size_t memSize) { void *temp = malloc(memSize); memcpy(temp, a, memSize); memcpy(a, b, memSize); memcpy(b, temp, memSize); free(temp); }