Path: utzoo!attcan!uunet!jarthur!nntp-server.caltech.edu!seismo.gps.caltech.edu!bruce From: bruce@seismo.gps.caltech.edu (Bruce Worden) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <1990Oct16.221035.10764@nntp-server.caltech.edu> Date: 16 Oct 90 22:10:35 GMT References: <2466@ux.acs.umn.edu> <15857@csli.Stanford.EDU> Sender: bruce@seismo.gps.caltech.edu (Bruce Worden) Organization: California Institute of Technology, CA Lines: 46 Nntp-Posting-Host: sis.gps.caltech.edu In article poser@csli.stanford.edu (Bill Poser) writes: >In article 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. [ .... ] >[ ... ] 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.) On the contrary, if this loop actually executed, the value of `strlen(duh)' would change at every iteration because `duh' is incremented in the loop. Similarly, in the final statement (deleted above): printf("%s\n",duh); `duh' would point off the end of the string if the loop actually executed. I sent the original poster this code with an explanation, which people may comment on as they see fit: #include main() { char *duh = "Hello"; int i, limit = strlen(duh); printf("%s\n", duh); for(i=0; i