Output badly formatted accented C characters in Visual Studio Code

Asked

Viewed 153 times

0

Although it is importing the library referring to accentuation, the outputs of the accented characters come out totally unnoticed of the normal.

This problem only happens in Visual Studio Code, the same code in Dev C works normal.

Below the code:

    #include <stdio.h>
    #include <stdbool.h> 
    #include <stdlib.h>
    #include <locale.h>

    bool E_Primo(int Numero){
        for (int i = 2; i < Numero; i++)
            if (Numero % i == 0)
                return false;
        return true;
    }

    int main(){
        setlocale(LC_ALL, "Portuguese");
        int Numero;
        printf("Digite um número para verificar se ele é primo ou não: ");
        scanf("%d", &Numero);
        
        while (Numero <= 0){
            printf("Número invalido para saber se é primo ou nao\nDigite uma número maior que 0");
            scanf("%d", &Numero);
        }  
        
        if (E_Primo(Numero))
             printf("Seu número %d é primo ", Numero);
        else
             printf("Seu número %d não é primo ", Numero);
    
        return 0;
    }
  • 2

    Depending on the terminal that is configured in VS Code this is within the expected. Not every terminal supports characters beyond the ASCII table.

  • 1

    In my personal experience, you should not use another language other than English in a source code, as this has always been and will be a problem, since there are dozens of tables and forms of accented character encoding. Vscode may be using UTF-8. This may work well on Linux but will be a disaster on a Windows terminal. The correct one, although not trivial for a small program, is to use a library that will use a table to "translate" to another language. That’s another problem, of course.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.