Problem with sorting

user01 Reply 9 years 25 weeks ago
I am using qsort to sort the array but it doesn't work.
pichulia Reply 9 years 25 weeks ago
Good Question. look at your comparision function /* ensure the result is either 1, 0 or -1 */ if((*Word1)->Word < (*Word2)->Word) { Result = -1; } else if((*Word1)->Word > (*Word2)->Word) { Result = 1; } and typedef struct WORD { char *Word; (*Wordx)->Word type is char*. Do you know how pointer values be saved at memory? they are 8byte integer form; The address of memory. Let you comparing like this : (*W)->Word > (*W)->Word This mean "Compare the address of memory", not "Compare the string". If you want to compare the string, use strcmp((*W)->Word, (*W)->Word); or...just make strcmp. And...I don't like copy sourcecode. I just want to say this for you..... https://github.com/HenryNi/mycode/blob/master/C/c_lang_book/krx60410.c