C - when I use the local.h scanf does not work well

0

I'm creating a database.

I used locale.h and setlocale(LC_ALL, "Portuguese") so that accents and keys appear on the windows command line.

Because of this, when I make a% w / o of a character with an accent or a cue and make the corresponding% w / o, it prints a non-existent symbol in the alphabet and the corresponding value in decimal is a negative number.

If the special character is not entered by scanf (or fgets) and you already have in the code the program 'prints' it normally

I've done some research on the subject and found a lot of information about the various types of coding and unicode but nothing about why this happens.

I leave my code:

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

int main() {

    setlocale(LC_ALL, "Portuguese") ;

    /* Para ver a tabela ASCII */

    int x ;

    for(x = 0; x <= 255; x++) {

        printf("[%d]: %c\n", x, x);
    }

    char ch ;

    printf("Introduzir caractere: ")
    scanf("%c", &ch) ;
    printf("Caractere introduzido: %c\n", ch);
    printf("Valor na tabela ASCII: %d\n", ch);
}

entering, for example, an "ç" the character that prints is "╬" and the decimal value is -121. The same goes for other accent characters.

Why is this happening?

    
asked by anonymous 10.12.2017 / 07:39

0 answers