Qsort - Sort array of strings

Discussion in 'C' started by parthipanvelu, Nov 11, 2008.

  1. parthipanvelu

    parthipanvelu New Member

    Joined:
    Nov 11, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi , Can any one help me in this regard?

    below is the code snippet I used to sort an array of strings

    Code:
    int cstring_cmp(const void *a, const void *b)
     {
       const char **ia = (const char **)a;
       const char **ib = (const char **)b;
       return strcmp(*ia, *ib);
       /* strcmp functions works exactly as expected from
       comparison function */
     }
     int removeDuplicates(int count,int k)
     {
      int i=0,j=0;
      char All[150][20];
      int y=1;
     
      
      if(count==0)
      {
       return 0;
      }
      
      for(i;i<count;i++)
      {
                if(k==1)//if the Non-Html is GIF
               {
                      sprintf(All[i],"{GIF_%d}",(i+1));//Save the "GIF" elements in "ALL[i]" array
               }
     
      }
            qsort(All, 150, 20, cstring_cmp);
     
      for(i;i<count;i++)
      {
       if(strcmp(All[i],All[i+1])==0)
       {
       }
       else
        y++;
      }
      return y;
      
     }

    over her i am capturing some values in the loadrunner and storing them in a string array. i need these values to be sorted and retrieve the count of the unique values only. I am facing a Memory violation error in the line qsort. Can anyone help me solving this. the code is compiling without errors.
     
    Last edited by a moderator: Nov 11, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice