compare strings, strcmp
Robert Osborne
robert at isgtec.UUCP
Sat Nov 18 07:10:55 AEST 1989
In article <11605 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <4463 at blake.acs.washington.edu> jimli at 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 | <HEY BUD, get off the box, it's my turn!>
...utzoo!lsuc!isgtec!robert | oops, sorry about that.
More information about the Comp.lang.c
mailing list