Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!uwm.edu!bionet!agate!shelby!csli!poser From: poser@csli.Stanford.EDU (Bill Poser) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <15857@csli.Stanford.EDU> Date: 16 Oct 90 19:53:23 GMT References: <2466@ux.acs.umn.edu> Reply-To: poser@csli.stanford.edu (Bill Poser) Organization: Center for the Study of Language and Information, Stanford U. Lines: 20 In article <2466@ux.acs.umn.edu> edh@ux.acs.umn.edu (Eric D. Hendrickson) writes: [believes that there is a problem with toupper and gives code including the following] > > char *duh = "Hello"; > printf("%s\n", duh); > while (*duh <= strlen(duh)) { > if (islower(*duh)) *duh = toupper(*duh); > *duh++; > } The problem here is in the while termination condition. What this tests is whether the numerical value of the current character (*duh) is less than or equal to the length of the the string duh, which happens always to be five. This condition is never satisfied, so the code in the loop is never executed. (An aside: since strlen(duh) never changes, either you or the compiler should move it outside the loop.) Bill