在C中使用UTF-8符号绘制TicTacToe字段

在C中使用UTF-8符号绘制TicTacToe字段,c,arrays,utf-8,tic-tac-toe,wchar-t,C,Arrays,Utf 8,Tic Tac Toe,Wchar T,我有一个小Tictaoe游戏,用standart ANSII符号绘制Tictaoe区域。这是我正常的绘图区域功能: void drawField(char *field) { printf(" ________________________\n"); printf(" | | | |\n"); printf(" | %c | %c | %c |\n", field[0],

我有一个小Tictaoe游戏,用standart ANSII符号绘制Tictaoe区域。
这是我正常的
绘图区域
功能:

void drawField(char *field) {

printf("            ________________________\n");
printf("            |       |       |      |\n");
printf("            |   %c   |   %c   |   %c  |\n", field[0], field[1], field[2]);
printf("            |_______|_______|______|\n");
printf("            |       |       |      |\n");
printf("            |   %c   |   %c   |   %c  |\n", field[3], field[4], field[5]);
printf("            |_______|_______|______|\n");
printf("            |       |       |      |\n");
printf("            |   %c   |   %c   |   %c  |\n", field[6], field[7], field[8]);
printf("            |_______|_______|______|\n");

} 
我们大学的导师/导师刚刚用UTF-8字符创建了同一领域,如┌ ┐└ ┘├, ... . 他在Mac电脑上完成了这项工作,并在简单的苹果文本编辑器Gnu编译器中编写了整个程序。所以我让他把他的drawField函数的代码发给我:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
char* getcharacter(char character){
switch(character){
    case 'x':
        return "\u2620";
    case 'o':
        return "\u2622";
    case '0':
        return "\u24EA";
    case '1':
        return "\u2460";
    case '2':
        return "\u2461";
    case '3':
        return "\u2462";
    case '4':
        return "\u2463";
    case '5':
        return "\u2464";
    case '6':
        return "\u2465";
    case '7':
        return "\u2466";
    case '8':
        return "\u2467";
    default:
        return " ";
   }
}

void drawField(char *field){
printf("\033[H\033[J");
printf("\u250F\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2513\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[0]), getcharacter(field[1]), getcharacter(field[2]));
printf("\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[3]), getcharacter(field[4]), getcharacter(field[5]));
printf("\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[6]), getcharacter(field[7]), getcharacter(field[8]));
printf("\u2517\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u251B\n");
}
#包括
#包括
#包括
char*getcharacter(char字符){
开关(字符){
案例“x”:
返回“\u2620”;
案例“o”:
返回“\u2622”;
案例“0”:
返回“\u24EA”;
案例“1”:
返回“\u2460”;
案例“2”:
返回“\u2461”;
案例“3”:
返回“\u2462”;
案例“4”:
返回“\u2463”;
案例“5”:
返回“\u2464”;
案例“6”:
返回“\u2465”;
案例“7”:
返回“\u2466”;
案例“8”:
返回“\u2467”;
违约:
返回“”;
}
}
无效绘图字段(字符*字段){
printf(“\033[H\033[J”);
printf(“\u250F\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2533\u2501\u2501\u2501\u2513\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\u2503\n”),getcharacter(字段[0]),getcharacter(字段[1]),getcharacter(字段[2]);
printf(“\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\n”),getcharacter(字段[3]),getcharacter(字段[4]),getcharacter(字段[5]);
printf(“\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\u2503\n”),getcharacter(字段[6]),getcharacter(字段[7]),getcharacter(字段[8]);
printf(“\u2517\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u251B\n”);
}
我在Visual Studio 2015中编码,对我来说,转义序列当然不起作用-它们只是一堆

所以我试着让这些字段中的符号至少起作用:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
wchar_t sym = ' ';
wchar_t getcharacter(char character) {
switch (character) {
case 'X':
    sym = L'\u2620';
    return sym;
case 'O':
    sym = L'\u2622';
    return sym;
case '1':
    sym = L'\u2460';
    return sym;
case '2':
    sym = L'\u2461';
    return sym;
case '3':
    sym = L'\u2462';
    return sym;
case '4':
    sym = L'\u2463';
    return sym;
case '5':
    sym = L'\u2464';
    return sym;
case '6':
    sym = L'\u2465';
    return sym;
case '7':
    sym = L'\u2466';
    return sym;
case '8':
    sym = L'\u2467';
    return sym;
case '9':
    sym = L'\u2468';
    return sym;
default:
    sym = ' ';
    return sym;
    }
}

void drawField(char *field) {
printf("\033[H\033[J");
printf("\u250F\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2513\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[0]), getcharacter(field[1]), getcharacter(field[2]));
printf("\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[3]), getcharacter(field[4]), getcharacter(field[5]));
printf("\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n");
printf("\u2503 %s \u2503 %s \u2503 %s \u2503\n", getcharacter(field[6]), getcharacter(field[7]), getcharacter(field[8]));
printf("\u2517\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u251B\n");
} 
#包括
#包括
#包括
wchar_t sym='';
wchar\u getcharacter(字符字符){
开关(字符){
案例“X”:
sym=L'\u2620';
返回符号;
案例“O”:
sym=L'\u2622';
返回符号;
案例“1”:
sym=L'\u2460';
返回符号;
案例“2”:
sym=L'\u2461';
返回符号;
案例“3”:
sym=L'\u2462';
返回符号;
案例“4”:
sym=L'\u2463';
返回符号;
案例“5”:
sym=L'\u2464';
返回符号;
案例“6”:
sym=L'\u2465';
返回符号;
案例“7”:
sym=L'\u2466';
返回符号;
案例“8”:
sym=L'\u2467';
返回符号;
案例“9”:
sym=L'\u2468';
返回符号;
违约:
sym='';
返回符号;
}
}
无效绘图字段(字符*字段){
printf(“\033[H\033[J”);
printf(“\u250F\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2533\u2501\u2501\u2501\u2513\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\u2503\n”),getcharacter(字段[0]),getcharacter(字段[1]),getcharacter(字段[2]);
printf(“\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\n”),getcharacter(字段[3]),getcharacter(字段[4]),getcharacter(字段[5]);
printf(“\u2523\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u254B\u2501\u2501\u2501\u252B\n”);
printf(“\u2503%s\u2503%s\u2503%s\u2503\u2503\n”),getcharacter(字段[6]),getcharacter(字段[7]),getcharacter(字段[8]);
printf(“\u2517\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u253B\u2501\u2501\u2501\u251B\n”);
} 

我必须承认,我对C语言中的UTF-8打印一无所知-有人能帮我吗?

Windows使用UTF-16,所以你需要调整你的代码。但它们不是Unicode转义序列吗?@Let_me__________,这些是Unicode点。使用特定于平台的编码是个坏主意。I/o库通常处理输出编码,这有帮助吗:?您没有收到编译器警告c4566()?