compare strings, strcmp

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Nov 19 11:54:00 AEST 1989


In article <2742 at munnari.oz.au> ok at mudla.cs.mu.OZ.AU (Richard O'Keefe) writes:
>> In article <11605 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>> >Dump it into an external file and invoke the system sort utility on the file.
>A general point about questions like this:  any answer we give is likely
>to be an answer to the wrong question.  I find myself wondering why anyone
>wants to sort char array[10000][200].

That was the main point that I wanted to call attention to.

>There is another extremely important reason why Doug Gwyn's suggestion is
>a REALLY good one even if it proves slower in some cases.  That is that
>the system sort utility provides you with a mini-language for specifying
>comparisons which can make it a lot easier to get your sort right.

That may or may not be important, depending on the application.
One thing one should always try to keep in mind is that for problems
like sorting, much effort has already been invested in finding good
solutions, and it is likely to be counterproductive to spend one's
own limited time reinventing wheels poorly when good wheels are
sitting on the shelf.

qsort() probably suffices for this case, system("sort ...") for complex
key matching requirements (too bad a comparable binary-record sort
utility isn't a standard UNIX utility), and if none of the existing
tools has the right properties only THEN would one program his own
sorting algorithm.



More information about the Comp.lang.c mailing list