Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!cass.ma02.bull.com!mips2!bbn.com!pdsmith From: pdsmith@bbn.com (Peter D. Smith) Newsgroups: comp.lang.c Subject: Re: strcmp Message-ID: <64771@bbn.BBN.COM> Date: 19 Jun 91 22:42:59 GMT References: <2695@m1.cs.man.ac.uk> <1991Jun18.074029.12226@panix.uucp> Sender: news@bbn.com Reply-To: pdsmith@spca.bbn.com (Peter D. Smith) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 11 In article <1991Jun18.074029.12226@panix.uucp> yanek@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