Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!orc!inews!cmdnfs!bhoughto From: bhoughto@cmdnfs.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Is there a good example of how toupper() works? Message-ID: <469@inews.intel.com> Date: 16 Oct 90 21:05:28 GMT References: <2466@ux.acs.umn.edu> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 36 In article <2466@ux.acs.umn.edu> edh@ux.acs.umn.edu (Eric D. Hendrickson) writes >#include >main() >{ > char *duh = "Hello"; > printf("%s\n", duh); > while (*duh <= strlen(duh)) { Change `*duh' to `duh'. > if (islower(*duh)) *duh = toupper(*duh); > *duh++; Ditto. Increment the pointer, not the character. > } > printf("%s\n", duh); Use a different variable here. `duh' will now point to 'O', not 'H', if the loop is entered. >} > >And what I get is : >Hello >Hello Basically, since `*duh' is a character, and a printable one at that, its value as an integer in (*duh <= strlen(duh)) is going to be something on the order of 60, while strlen(duh) is 5. The loop is skipped because 60 is never <= 5. --Blair "End of lesson. No opportunistic comment on use of the word 'duh.' ...except maybe indirectly..."