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

Steve L Vissage II svissag at hubcap.clemson.edu
Fri Oct 19 01:29:54 AEST 1990


>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)
 
You don't even have to do any casts, because C is pretty free with it's
int<->char conversions.

> void strupper(char *str)
> {
> for (;*str!='\0';str++)
>        *str=islower(*str)?toupper(*str):*str;
> }                  ^
                     | 
         *str=toupper(*str);
              
Steve L Vissage II



More information about the Comp.lang.c mailing list