Path: utzoo!censor!isgtec!robert From: robert@isgtec.UUCP (Robert Osborne) Newsgroups: comp.lang.c Subject: Re: compare strings, strcmp Summary: What's wrong with StrEq? Yes, use qsort! Keywords: strcmp,strings Message-ID: <214@isgtec.UUCP> Date: 17 Nov 89 20:10:55 GMT References: <4463@blake.acs.washington.edu> <11605@smoke.BRL.MIL> Reply-To: robert@isgtec.UUCP (Robert Osborne) Organization: ISG Technologies Inc., Mississauga, Ontario Lines: 33 In article <11605@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <4463@blake.acs.washington.edu> jimli@blake.acs.washington.edu (Jimmy Li) writes: >>char array[10000][200]; >>What is the fastest way to sort this array? > >Dump it into an external file and invoke the system sort utility on the file. This is a REALLY bad way of sorting an array this big. Write ~2M to disk, perform a system call (a fork of at least 2M) which reads ~2M from disk, sorts it, and writes ~2M back to disk, then read ~2M from disk. He asked for the FASTEST way, this shouldn't even have be given as an option. >You could also use qsort(), [...] ^^^^^^^ Probably your best bet! Use Doug's macro (below) for the compare function. Note the problem some qsort()'s have with "nearly sorted" data. If you REALLY need speed implement a sort of your own, BUT only if qsort() isn't fast enough (it should be). >but this is such a ridiculously large amount >of storage to statically allocate that you should be thinking of alternatives. Maybe all his program *does* is work with 10000 character strings of length 200 :-). Why calloc this space as the first line of your main? >#define StrEq( a, b ) (*(a) == *(b) && strcmp( a, b ) == 0) /* UNSAFE */ This is a great macro mind if I use it? But I see it has started another bout of comp.lang.c.morons, shame on you Doug :-) Rob. -- Robert A. Osborne | I take full responsibility for the opin... ...uunet!mnetor!lsuc!isgtec!robert | ...utzoo!lsuc!isgtec!robert | oops, sorry about that.