-2
Recently I’ve been working on a C project that involves printing some strings in a txt file. However, when I put special characters and accents are printed some strange symbols, like ‡ and Æ. I made an example code showing more or less what I need.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(int argc, char *argv[]) {
setlocale(LC_ALL, "Portuguese");
char teste[100];
printf("Frase: "); /*Usei a Frase "Gabriel Fogaça não perguntará em vão" para os testes*/
gets(teste);
printf("\n\nResultado: %s\n", teste);
FILE* arq = fopen("teste.txt", "w+");
fprintf(arq, "%s", teste);
fclose(arq);
return 0;
}
By the way, when I use "setlocale" the print gets bugged up at the prompt, but that’s the least. What I really need is to be able to print the string in the txt file.
I circled without using this function and actually the result in the terminal normalized, but in the txt file continue to appear symbols in place of the special characters :(
– Gabriel Foraza
It is, but then probably the problem is in the charset configuration of your editor, which is not UTF-8. It is not your program’s fault.
– epx
Aaah got it. I’ll try to change the settings then. Thanks a lot for the help!!
– Gabriel Foraza
I was able to change the settings of the editor and now the charset is in UTF-8. Still the error continues :(
– Gabriel Foraza