Ryan Allen wrote:

> So I have a huge array of structures, and when I run qsort to sort on
> a key, it zeros out my entire array!!!! I have looked up every book I
> could find on C and I think this is okay....but the results tell all!

> /*  Data def.    */
> typedef struct uu_rec
> {
>         char            username[50];
>         int             bytesSent;
>         int             bytesRecieved;
>         char            trans_date[30];
> } UU_Record; 
> /* create the array     */
> UU_Record       data_list[15000]; 
> 
> 
> /* -----------------
> * A bunch of code goes here 
> * to fill data_list with data
> *  -----------------*/
> 
> 
> int my_strcmp(const void *a, const void *b)
> {    return strcmp( ((UU_Record *)a)->username,((UU_Record*)b)->username); 
> }
> 
> 
> /*  Call the sort function  */
> qsort(data_list, 15000, sizeof(UU_Record), my_strcmp);

Do you really have 15000 defined elements in the array? If not, the
undefined elements (which will be all zeroes) will come first. E.g. if 
you have 10 defined elements, after the qsort, the 14990 undefined
elements will come first, and the 10 defined elements will be at the
end of the array.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to