MikeCopeland <
mrc...@cox.net> wrote in news:MPG.30976e1acf2e5c9e9896b6
@
news.eternal-september.org:
> In article <
C-201510...@ram.dialup.fu-berlin.de>, r...@zedat.fu-
>
berlin.de says...
>> >the "toupper(char(cz))" is yeilding 67, not C. What am I doing
> wrong?
>>
>> 67 /is/ 'C'! (Assuming ASCII)
>
> Indeed it is, but I want the output to be "C", not "67".
> Is my cast operation wrong?
Yes, cz is already a char, so there is no point to cast it to char again.
On the other hand, result of toupper() is an int and needs to be somehow
converted back to char. I.e. instead of
toupper(char(cz))
you need
char(toupper(cz)).
>
> ostringstream ossz;
> int nx1 = 2;
> char cz = char(nx1+'a');
> ossz.str(""), ossz << "2" << setfill('0') << setw(2)
> << (nx1+1) << toupper(char(cz))
> << char(cz);
>
PS. Note that toupper() behavior is undefined for most negative input
values (and char is signed in common implementations), so if you are not
100% sure your texts are ASCII-only one should better check for that or
at least cast cz to unsigned char before passing to toupper.