Negative ASCII value

前端 未结 6 1401
太阳男子
太阳男子 2020-12-09 19:33

What\'s the point of negative ASCII values?

int a = \'«\'; //a = -85 but as in ASCII table \'<<\' should be 174
6条回答
  •  盖世英雄少女心
    2020-12-09 20:00

    I had this artifact. When you use char as symbols you have no problem. But when you use it as integer (with isalpha(), etc.) and the ASCII code is greater then 127, then the 'char' interpret as 'signed char' and isalpha() return an exception. When I need use the 'char' as integer I cast the 'char' to unsigned:

    • isalpha((unsigned char)my_char);

    @n0rd: koi8 codepage uses ascii from 128 to 255 and other national codepages: http://www.asciitable.com/

提交回复
热议问题