qsort() and strings/numbers

This is a discussion on qsort() and strings/numbers within the C Programming forums, part of the General Programming Boards category; Hi all! someone could help me to sort a string? char strings[10000][100]; The strings have letters and numbers. Ex.: 256_test ...

  1. #1
    ipe
    ipe is offline
    Registered User
    Join Date
    Jan 2003
    Posts
    52

    qsort() and strings/numbers

    Hi all!
    someone could help me to sort a string?

    char strings[10000][100];

    The strings have letters and numbers. Ex.:
    256_test
    test.435.433

    Code:
    /* qsort example */
    #include <stdio.h>
    #include <stdlib.h>
    
    int values[] = { 40, 10, 100, 90, 20, 25 };
    
    int compare (const void * a, const void * b)
    {
         return ( *(int*)a - *(int*)b );
    }
    
    int main ()
    {
         int * pItem;
         int n;
         qsort (values, 6, sizeof(int), compare);
         for (n=0; n<6; n++)
         {
            printf ("%d ",values[n]);
         }
         return 0;
    }
    in this example (I found on google) I didn't understand the function compare. I think this one is just for numbers. What should I do to sort string and numbers?
    Thank you in advance!

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    1

Popular pages Recent additions subscribe to a feed

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