Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
Why Unicode characters are not displayed properly in terminal with GCC?

I've written a small C program:

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

int main() {
    wprintf(L"%s\n", setlocale(LC_ALL, "C.UTF-8"));
    wchar_t chr = L'┐';
    wprintf(L"%c\n", chr);
}

Why doesn't this print the character ┐ ?

Instead it prints gibberish. unicodetest

I've checked:

  • tried compiling without setlocale, same result
  • the terminal itself can print the character, I can copy-paste it to terminal from text-editor, it's gnome-terminal on Ubuntu
  • GCC version is 4.8.2
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

wprintf is a version of printf which takes a wide string as its format string, but otherwise behaves just the same: %c is still treated as char, not wchar_t. So instead you need to use %lc to format a wide character. And since your strings are ASCII you may as well use printf. For example:

int main() {
    printf("%s\n", setlocale(LC_ALL, "C.UTF-8"));
    wchar_t chr = L'┐';
    printf("%lc\n", chr);
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda