I suspect it's because your char i
defaults to signed
. When you add 23
to a lowercase letter, anything that is above 104
(being 127-23
) is going to wrap around into negatives. Looking at your code, it will stay negative because it fails the subsequent tests and does not get modified.
It's usually best to do char
arithmetic with int
, then convert back to char
... But you could probably fix this by using unsigned char
.