toupper() side effects (was Re: evaluation order)
Dave Hammond
daveh at marob.masa.com
Sat Sep 16 12:19:23 AEST 1989
In article <9366 at attctc.Dallas.TX.US> bobc at attctc.Dallas.TX.US writes:
>[...] I figured that it would have been simpler to do something like
>
> while (((ch = toupper(getch())) != 'Y') && (ch !='N'));
>
Note that some implementations of toupper() (SunOS comes to mind)
will return the wrong result if passed a non-lowercase argument.
You'd probably want to expand this line and run an islower()
test on the argument to toupper:
int temp;
while ( ((ch = (islower(temp=getch())
? toupper(temp)
: temp)) != 'Y') && (ch !='N'));
--
Dave Hammond
daveh at marob.masa.com
More information about the Comp.lang.c
mailing list