Is there a good example of how toupper() works?
Bruce Worden
bruce at seismo.gps.caltech.edu
Fri Oct 19 04:26:50 AEST 1990
svissag at hubcap.clemson.edu (Steve L Vissage II) writes:
>From article <1990Oct17.170914.683 at wpi.WPI.EDU>, by profesor at wpi.WPI.EDU (Matthew E Cross):
>> Nope, won't work - the return value of 'toupper' is undefined if the input is
>> not a lowercase character.
>
>So define your own toupper() macro. That's what I did.
>#define toupper(ch) ((ch<123 && ch>96) ? ch-32 : ch)
> [ ... ]
I wouldn't recommend defining a macro with the same name as a library
function. And from what I remember from the `toupper()' and `tolower()'
discussion here about three months ago, I think it was generally agreed
that a macro that evaluates its argument three times must be used with
great caution ( toupper(getchar()) can happen, e.g.), and that the simple
subtraction ( ch-32 ) and comparisons ( ch<123, ch>96) are inherently
non-portable.
P.S. I, among others, missed the *duh = "hello"; bug. My apologies.
--------------------------------------------------------------------------
C. Bruce Worden bruce at seismo.gps.caltech.edu
252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125
More information about the Comp.lang.c
mailing list