getche() 将特殊字符显示为另一个值

getche() showing special character as another value

我正在做一个编码练习,我在 c 中使用 getche() 读取用户输入,因为我是葡萄牙语,所以我需要让用户输入葡萄牙语特殊字符,例如“Á”等... 而且我似乎无法在屏幕上输出那些,它可以很好地保存字符,但是例如当我按“Á”时它会在屏幕“µ”中显示 以下代码是我使用 getche():

读取用户输入的部分
int counter = 0;
    int inner_counter = 0;
    int amount = 0;
    int entrada = 0;
    int especiais[16] = {128, 144, 181, 192, 183, 199, 210, 212, 214, 224, 226, 227, 228, 233, 234, 235};

    printf("\nAqui apenas sera aceite letras Maisculas e espaço!\n");
    printf("Introduza quantos caracteres deseja inserir!\n");
    scanf("%d", &amount);

    int array_tipo1[amount];  //array dinamico, tamanho com base na preferencia do user, dynamic array

    for(counter=0;counter<amount;counter++){
        entrada = getche();  #where i read the input FIX: entrada = getwchar();

        if((entrada >= 65 && entrada <= 90) || (entrada == 32)){
            array_tipo1[counter] = entrada;
        }

        else if(entrada >= 128){
            for(inner_counter=0;inner_counter<16;inner_counter++){
                if (entrada == especiais[inner_counter]){
                    array_tipo1[counter] = entrada;
                }
            }
        }

        else{
            array_tipo1[counter] = '[=10=]';
        }
    }

    for(counter=0;counter<amount;counter++){
        if(array_tipo1[counter] != '[=10=]'){
            printf("\n%c\n", array_tipo1[counter]);
        }
    }

数字我使用 ASCII table 数字引用我将让用户输入的字符 提前感谢大家!

您尝试使用的带有重音符号的字母是多个字节,getche() 仅使用第一个字节。要使用这些字符,您必须改用 getwche()。