Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.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: <15862@csli.Stanford.EDU> Date: 16 Oct 90 23:11:05 GMT References: <2466@ux.acs.umn.edu> <15857@csli.Stanford.EDU> <473@inews.intel.com> Reply-To: poser@csli.stanford.edu (Bill Poser) Organization: Center for the Study of Language and Information, Stanford U. Lines: 35 In article <473@inews.intel.com> bhoughto@cmdnfs.intel.com (Blair P. Houghton) writes: >In article <15857@csli.Stanford.EDU> poser@csli.stanford.edu (Bill Poser) writes: >>The problem here is in the while termination condition. What this tests > >There's more than just the one problem (that *duh will be > strlen(duh)); > >0. *duh refers to the character, not the location; This is one aspect of the problem I pointed out, that comparing the value of a character to the length of the string is not useful. >1. The loop changes the value of the pointer `duh', so it may print >nothing other than "O" once you get the loop to work; This will be avoided if an index is used and compared to strlen(duh). The issue only arises if one compares duh to duh+strlen(duh), in which case a copy of the pointer must be used. >2. merely using (duh <= strlen(duh)) won't fix it; the >value of the pointer `duh' is almost certain to be larger >than strlen(duh). Another aspect of the same problem I pointed out. Why worry about an obviously wrong "fix" that nobody has suggested? The problem doesn't have to do with dereferencing - it has to do with confusing pointers and indices. >>(An aside: since strlen(duh) never changes, either you or the compiler >>should move it outside the loop.) > >Trivial optimization compared to the massive bugs extant. Which is why its an aside. Bill