Is there a good example of how toupper() works?

Bill Poser poser at csli.Stanford.EDU
Wed Oct 17 09:11:05 AEST 1990


In article <473 at inews.intel.com> bhoughto at cmdnfs.intel.com (Blair P. Houghton) writes:
>In article <15857 at csli.Stanford.EDU> poser at 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



More information about the Comp.lang.c mailing list