sort not working why??

This is a discussion on sort not working why?? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int intcmp(const void *v1, const void *v2); int main(void) { char *array[8] = ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    sort not working why??

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int intcmp(const void *v1, const void *v2);
    
    int main(void)
    {
       char *array[8] = { "India", "Africa","America","London","Neyyork","Newjersy","WestLife","Fremee"};
       int cnt,i;
       cnt = sizeof(array)/sizeof(array[0]);
    
       printf("%d", cnt);
    
       qsort(array , cnt , sizeof( array[0]) , intcmp);
    
       for ( i = 0;  i < 8; i++ ){
           printf("%s\n", array[i] );
       }
    
    
    
          system("PAUSE");
          return 0;
    }
    int intcmp(const void *v1, const void *v2)
    {
          return (*(int *)v1 - *(int *)v2);
    }
    It isnt sorting the char *array why ??? thanks and yeah one more thing .I am making a address book programm so where can i download the codes for the address book contest that was done before ... Thansk
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Probably because your comparison function sucks? You're comparing strings. Ever hear of strcmp?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Originally posted by quzah
    Probably because your comparison function sucks? You're comparing strings. Ever hear of strcmp?

    Quzah.
    Dam me how could i have missed that....wheres my dam gun *Click* *BANG*
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by datainjector
    Dam me how could i have missed that....wheres my dam gun *Click* *BANG*
    lol, your shiz is all ready to sort an array of ints
    hello, internet!

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    WOW!

    WOW! whats wrong with me today first this question ,second the maze question well i just deleted that one did want to get more embarest .....Is it the weather ....hummmm... better get some carona ...chilled as i like it
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  2. Jumbo Frames - sort of working
    By bj00 in forum Networking/Device Communication
    Replies: 1
    Last Post: 07-23-2007, 11:29 AM
  3. vector: sort multiple fields
    By FoodDude in forum C++ Programming
    Replies: 4
    Last Post: 09-28-2005, 12:00 PM
  4. Merge Sort Not Working!!!
    By Aakash Datt in forum C++ Programming
    Replies: 0
    Last Post: 05-28-2003, 06:56 PM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 08:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21