Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: multi-character character constant [-Wmultichar]

Tags:

c

wchar-t

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] .

like image 519
billpcs Avatar asked May 13 '14 14:05

billpcs


1 Answers

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.

like image 59
ecatmur Avatar answered Oct 18 '22 16:10

ecatmur