how to implement qsort function in c, data structure

Hi!

I am needing help in implementing the qsort function to sort an array of 100 words in an array char words[100][6] in ascending order. Each of the words are 5 char long. I have seen different ways of impelmenting it but still can't figure all of that out. I know I need a compare function. Please shed some light on this.
Thanks!
Vashudev

Comments

  • Hello Donotalo!

    Your reply to my question can't be found. It gives some error in path. Please post again, appreciate it.
    Vashudev






    : Hi!
    :
    : I am needing help in implementing the qsort function to sort an array of 100 words in an array char words[100][6] in ascending order. Each of the words are 5 char long. I have seen different ways of impelmenting it but still can't figure all of that out. I know I need a compare function. Please shed some light on this.
    : Thanks!
    : Vashudev
    :

  • [b][red]This message was edited by stober at 2006-4-30 5:32:7[/red][/b][hr]

    First, write your own comparison function and pass that to qsort
    [code]
    int compare(const void* p1, const void* p2)
    {
    return strcmp((const char*)p1,(const char*)p2);
    }

    int main()
    {
    ...
    qsort(words,100,6, compare);
    }
    [/code]



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories