Please somebody help
How to use qsort to sort arrays of chars...
The way I understand qsort is that qsort will sort pointers to an array, but array itself (in my case mystr) will remain unchanged. Is this correct?
How to use qsort to sort arrays of chars...
Code:
int sproxy(const void* pe1, const void* pe2) {
return strcmp(*(const char**)pe1,*(const char**)pe2);
}
int main() {
char mystr[5][50];
strcpy(mystr[0], "bbbb");
strcpy(mystr[1], "aaaa");
strcpy(mystr[2], "cc");
strcpy(mystr[3], "2222");
/* I thought I can send pointer to first element of my array to qsort, but I thoutght wrong.
Below code doesn't work. Produces Segmential Fault */
char *sp = &mystr[0][0];
qsort(sp,4,sizeof(char*),sproxy);[/b]
}
The way I understand qsort is that qsort will sort pointers to an array, but array itself (in my case mystr) will remain unchanged. Is this correct?