Language utilized : C Language
IDE : Visual Studio Code
OS : Linux Ubuntu 20.04
Code level : I'm studying computer science in university since september.
Hello, I'm currently working on a game with a dice system, the overlay is the console. I'm drawing the dice with special characters from here : https://fr.wikipedia.org/wiki/Wikipédia:Caractères_spéciaux/Bordures (sorry it's the french version).
But sometimes, I need to change the look of them. So I created a table (actually multiple, but it's the same problem everywhere), and this table is made of characters. To define what is inside, I put an if/else module, and I just affect characters such as ┃ or ┳ in the cases of the table.
Problem : when I compile the code, I have a warning (-Wall) saying :
warning: overflow in conversion from ‘int’ to ‘char’ changes value from ‘14849195’ to ‘-85’ [-Woverflow]
Long story short, I just want to be able to affect these characters in my table (I tried with normal characters and it worked perfectly fine).
typedef int t_dice[5][2];
typedef char t_diceExtremite[5];
typedef char t_diceMiddle [5][2];
t_dice dice;
t_diceExtremite styleDiceTop,styleDiceBottom;
t_diceMiddle styleDiceMiddle;
for(i=0 ; i<5 ; i ){
if(dice[i][1]==1){
styleDiceTop[i] = '┳';
styleDiceMiddle[i][0] = '┣';
styleDiceMiddle[i][1] = '┫';
styleDiceBottom[i] = '┻';
}else{
styleDiceTop[i] = '━';
styleDiceMiddle[i][0] = '┃';
styleDiceMiddle[i][1] = '┃';
styleDiceBottom[i] = '━';
}
}
Note : I already wrote 'int i;', and I filled dice[][] with values earlier.
Example of a warning message (this is the same for every line) :
/home/myname/code/SAE_1.01/yams.c:82:37: warning: multi-character character constant [-Wmultichar]
82 | styleDiceMiddle[i][0] = '┣';
|
/home/myname/code/SAE_1.01/yams.c:81:31: warning: overflow in conversion from ‘int’ to ‘char’ changes value from ‘842347315’ to ‘51’ [-Woverflow]
CodePudding user response:
Use wide characters.
i.e.
typedef char t_diceExtremite[5]; -> typedef w_chart t_diceExtremite[5];
and
styleDiceMiddle[i][0] = '┣'; -> styleDiceMiddle[i][0] = L'┣';