Problem to print on screen a string with accent

Asked

Viewed 353 times

2

I would like a help, because when the user type his name with accent, when printing on the screen the name, appears disfigured.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <locale.h>        
    int main(){
    setlocale(LC_ALL, "Portuguese");
    char nome[50];

    printf("Olá, seja bem-vindo ao Colega de Quarto, como você se chama ?");
    setbuf(stdin, NULL);
    fgets(nome,50,stdin);
    printf("\n");
    printf("O que você deseja, %s ?\n\n", nome);

    return 0;
    }
  • What encoding the file was created in and is being edited ?

2 answers

1

setlocale (LC_ALL,"English");

add this line at the beginning of main and tell me if it worked

  • Oops, I forgot to write in the post, I will edit. But even with setlocale is giving this problem. I have no idea what it might be.

  • I just tested the code I think the problem is not in it, because the accents appeared here.

  • test it here and you will see that there is no problem https://repl.it/languages/c

  • is using which compiler?

  • I’m using Code Blocks, the problem will be the compiler maybe ?

  • Probably some wrong configuration sometimes uses dev c++ if you’ve started in Prog, but if you want to venture into stronger compilers, look for vs code or Atom.

  • I switched to Dev anyway and it worked

Show 2 more comments

1

Try replacing your setlocale(LC_ALL, "English"); with

setlocale(LC_ALL,"");
  • I also tried this and it didn’t work, I think the error is in the compiler .

  • I used the c++ dev to do the tests and it worked normally, try changing the compiler to see if it works

  • 1

    I tested it here and it worked, it’s the same compiler.

Browser other questions tagged

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