I posted the answer to this exact question about a month and a half
ago...think that should be in the archives....
Here it is again (in a very basic form):
/* The typedef is just to make the next line shorter */
int comparedescs(const void *d1, const void *d2)
{
typedef DESCRIPTOR_DATA DD;
return strcmp((*(DD **)d1)->character->name, (*(DD
**)d2)->character->name);
}
void do_whotest(CHAR_DATA *ch, char *argument)
{
DESCRIPTOR_DATA *d, *list[50];
int x, cnt;
for(cnt = 0, d = descriptor_list; d; d = d->next, cnt++)
{
if(d->character)
list[cnt] = d;
}
send_to_char("Before sort:\n\r", ch);
for(x = 0; x < cnt; x++)
printf_to_char(ch, "%s\n\r", list[x]->character->name);
qsort(list, cnt, sizeof(DESCRIPTOR_DATA *), comparedescs);
send_to_char("\n\rAfter sort:\n\r", ch);
for(x = 0; x < cnt; x++)
printf_to_char(ch, "%s\n\r", list[x]->character->name);
}
----- Original Message -----
From: "Ben" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, May 25, 2002 10:07 AM
Subject: Using Qsort
> I'm trying to make qsort put my who list in alphabetical order, but
whatever
> I try it always seems to (i think - go into an endless loop) and lag the
> whole server for a few minutes until linux kills the process... I havent
> even got up to the qsort stage.. just trying to make it put the players
into
> an array.. any ideas on how to do it?
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>