compare strings, strcmp

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Nov 16 09:48:00 AEST 1989


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.
You could also use qsort(), but this is such a ridiculously large amount
of storage to statically allocate that you should be thinking of alternatives.

>(I heard that 'strcmp' is slow if the strings are long. Why?)

No, strcmp() is not particularly slow unless the strings typically
differ only after the Nth character where N >> 1.  Many of us use
a macro like the following for simple string equality testing, to
save the function-call overhead for typical strcmp() implementations:

#define	StrEq( a, b )	(*(a) == *(b) && strcmp( a, b ) == 0)	/* UNSAFE */



More information about the Comp.lang.c mailing list