[Solved] Why passing char as parameter to islower() does not work correctly?


The question boils down to:

If I write this:

int x = 'ÿ';

x will be -1 but I’d like it to be 255.

It’s -1 because 'ÿ' is a char of value 0xff. But as char is signed on your platform, sign extension takes place when you assign it to an int.

The solution is to write:

int x = (unsigned char)'ÿ';

So instead of islower('ÿ') write islower((unsigned char)'ÿ').

2

solved Why passing char as parameter to islower() does not work correctly?