Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amelia!dell From: dell@amelia.nas.nasa.gov (Thomas E. Dell) Newsgroups: comp.mail.sendmail Subject: Re: undefined: strcasecmp? Message-ID: <2922@amelia.nas.nasa.gov> Date: 21 Aug 89 06:58:36 GMT References: <1989Aug16.191624.6076@hfh.edu> <475@esfenn.UUCP> Reply-To: dell@amelia.nas.nasa.gov (Thomas E. Dell) Followup-To: comp.lang.c Organization: NASA Ames Research Center, Moffett Field, CA Lines: 24 In article <475@esfenn.UUCP> dah@.UUCP (Darrin Hyrup) writes: >int cstrcmp(s1, s2) /* also known as strcasecmp() */ >register char *s1, *s2; >{ > while(tolower(*s1) == tolower(*s2++)) > if(*s1++ == '\0') > return(0); > return(tolower(*s1) - tolower(*--s2)); >} Not quite.. a number of versions of Unix have the result of tolower(c) undefined (read: wrong) if c is not uppercase. This is because #define tolower(c) ((c) + ' ') or something similar is used. If you #define your own, remember you can only have ONE (c) in the definition or you will have side effects problems, s2 being incremented twice or whatnot. I've also seen tolower() and toupper() done as functions in the C library. If this is the case, you have the overhead of two procedure calls for each character in the string. Poor. You're better off hacking up a cstrcmp the hard way.. -- Tom dell@amelia.nas.nasa.gov