Glynn,
Good eye!!!!
I actually figured it just about 2 hours ago. It was one of those "Coffee pot" eureka
moments that only C programmers can possibly understand.
I only had about 6000 records containing data...leaving me with 9000 empty
records.......
-----------------------------------------------------------
Ryan Allen
Seafloor Surveys International
[EMAIL PROTECTED]
desk: 206-956-3524
fax: 206-441-9308
-----------------------------------------------------------
-----Original Message-----
From: Glynn Clements [SMTP:[EMAIL PROTECTED]]
Sent: Thursday, November 12, 1998 12:23 PM
To: Ryan Allen
Cc: [EMAIL PROTECTED]
Subject: Re: Problems with qsort
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]>