>>qsort(array[c], length, sizeof(int), compare);
that is incorrect. You are sorting an array of char pointers not an array of integers qsort(array, c, sizeof(char*), compare);
Your compare function is also wrong. Why are you converting the char pointers to integers? I thought the strings are words? All you need is this?
int compare(const void* pnum1, const void *pnum2)
{
return strcmp((char*)pnum1, (char*)pnum2);
}
for (i = 0; i < length; i++)
{
cout << array [i] << endl;
}
wrong there too.length is the number of characters in the original string. What you want here is variable c, which is the number of valid pointers in array
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Yes, see this thread . Just change your compare function as shown in that thread.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343