I need to implement qsort in C and sort in reverse lexicographical order. I'm confused on how to create and call the comparison function. This is what I have so far..
qsort (strArr, numLines, sizeof(char*) , sort);
int sort(const void * str1, const void * str2) {
return (-1) * strcasecmp((char*) str1, (char*) str2);
};
Eclipse is telling me "'sort' undeclared (first use in this function)" on the qsort line, but I fear that's not my only problem. Any advice?
Thanks, Hristo
Revision... this is what my array looks like:
char **strArr = malloc(numLines * sizeof(char*));
fgets(output, 256, sourceFile);
strArr[i] = malloc(((int) strlen(output) + 1) * sizeof(char));
strcpy(strArr[i],output);