Path: utzoo!attcan!uunet!samsung!uakari.primate.wisc.edu!uflorida!travis!brad From: brad@SSD.CSD.HARRIS.COM (Brad Appleton) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <1301@travis.csd.harris.com> Date: 18 Oct 90 13:36:00 GMT References: <2466@ux.acs.umn.edu> Sender: news@travis.csd.harris.com Organization: Harris Computers Systems Division, Fort Lauderdale,FL Lines: 36 In article jh4o+@andrew.cmu.edu (Jeffrey T. Hutzelman) writes: >Try this one: > >void strupper(char *str) >{ >for (;*str!='\0';str++) > *str=toupper(*str); >} You need to be careful here! It all depends on your compiler. For some compilers, the toupper function/macro performs the functional equivalent of: c = (c - 'a') + 'A'; with other compilers, the functionality of toupper is more like this: if ( c >= 'a' && c <= 'z' ) c = (c - 'a') + 'A'; In other words, some compilers will blindly convert the character to uppercase, regardless of what the character was whereas other compilers will make sure the value is indeed lowercase before trying to modify it to be uppercase. You will have to double-check your documentation for this. I think that the BSD Unix/C toupper() MUST take a lowercase letter and has undefined results otherwise whereas the AT&T Unix/C toupper() will give the desired result even if the character was not lowercase to begin with (Im not 100% positive about that though, anyone care to enlighten me). ______________________ "And miles to go before I sleep." ______________________ Brad Appleton brad@travis.ssd.csd.harris.com Harris Computer Systems ...!uunet!hcx1!brad Fort Lauderdale, FL USA ~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~