2
Hello. I’m new to the community so if I’m doing something wrong please correct me. I’m starting to program in C, and I’d like to be able to accentuate my programs. I found materials about it on various websites and all ask to use the library locale. h and the command setlocale(LC_ALL,""). I’ve tried to change the contents inside the "" for "Portuguese", "Portuguese_brasil.1252" and "pt_BR_utf8". The only thing that happens is changing different characters to other characters that are not yet what I need. I found on the site http://linguagemc.com.br/localizacao-de-programas-com-locale-h/ a code that is below.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h> //necessário para usar setlocale
int main(void)
{
printf("\n****** Verificando a localidade corrente ********\n\n");
printf ("Localidade corrente: %s\n", setlocale(LC_ALL,NULL) );
printf("Não é possível usar acentuação ou ç corretamente...\n\n");
printf("\n****** Alterando para a localidade do sistema ********\n\n");
//alterando para o padrão do sistema operacional
printf("A localidade corrente agora é %s \n",setlocale(LC_ALL,""));
printf("Agora não tem mais problema algum!\n");
printf("Já posso usar acentuação e também o caracter ç...\n\n\n");
system("pause");
return 0;
}
And the output of that code on my computer is:
****** Checking the current location ********
Current locality: C No ®can be used correctly...
****** Changing to the system location ********
The current locality now is Portuguese_brazil.1252 Now it does not have any more problem! I can use§accent and also the character At§...
I tested the code on another computer and it worked correctly. I checked the Clion is in UTF-8, and my OS is in Brazilian Portuguese, as well as my keyboard.