Is there a good example of how toupper() works?
Matthew E Cross
profesor at wpi.WPI.EDU
Thu Oct 18 03:09:14 AEST 1990
In article <wb76pN600awOE3SaQz at andrew.cmu.edu> jh4o+ at andrew.cmu.edu (Jeffrey T. Hutzelman) writes:
>Try this one:
>
>void strupper(char *str)
>{
>for (;*str!='\0';str++)
> *str=toupper(*str);
>}
Nope, won't work - the return value of 'toupper' is undefined if the input is
not a lowercase character. Try:
void strupper(char *str)
{
for (;*str!='\0';str++)
*str=islower(*str)?toupper(*str):*str;
}
(I hope I got the '? :' syntax right...)
--
+----------------------------------------------------+------------------------+
| "The letter U has a lot of uses ... | Looking for | profesor at wpi.wpi.edu |
| I like to play it like a guitar!" | suggestions +------------------------+
| -Sesame Street | for new gweepco programs... |
More information about the Comp.lang.c
mailing list