strcmp

Peter D. Smith pdsmith at bbn.com
Thu Jun 20 08:42:59 AEST 1991


In article <1991Jun18.074029.12226 at panix.uucp> yanek at panix.uucp (Yanek Martinson) writes:
>For intcmp(a,b) why not just use a-b ? That will tell you if they are equal
>and if not, which is greater.
>
>For strcmp(s,t): while(*s++==*t++&&*s&&*t); return *s-*t;

a-b will NOT tell you which is larger.  Instead it will overflow and
either return the wrong answer or call the fatal-error trap and
abruptly end the experiment.

					Peter D. Smith



More information about the Comp.lang.c mailing list