warning: multi-character character constant [-Wmultichar]

别来无恙 提交于 2019-12-19 18:30:26

问题


I want to have an Array of the Greek alphabet and this is what I do:

wchar_t pcletters[30] = {'α' , 'ά' , 'β' , 'γ' , 'δ' , 'ε' , 'ζ' , 'η', 'θ' , 'ι' , 'κ' , 'λ' , 'μ' , 'ν','ξ' , 'ο' , 'π' , 'ρ' , 'σ' , 'τ' , 'υ' , 'φ' , 'χ' , 'ψ' , 'ω', 'έ' , 'ή' , 'ί' , 'ό' , 'ύ' , 'ώ'} ;

I also include <locale.h> and have a line setlocale(LC_CTYPE, "") .

However I get the warning warning: multi-character character constant [-Wmultichar]. Moreover when I get to check if one of this letters is in a user input by doing :

if (userword[i] == pcletters[j]) {//do stuff} 

it does not seem to work. -Why do I get this warning ? -Is there a way to change pcletters in a way to be able to compare the userword[i] == pcletters[j]

Note: userword is defined like this: wchar_t userword[40] .


回答1:


Use wide character literals:

wchar_t pcletters[30] = {L'α' , ...
                         ^

Note that this will only work on platforms where the letters you are writing are a single wide character; this should work on Windows, where wchar_t is UCS-2.



来源:https://stackoverflow.com/questions/23633502/warning-multi-character-character-constant-wmultichar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!