How to solve accentuation problems when using the setlocale function?

5

I'm trying to set the program language to Portuguese, using setlocale(LC_ALL,"Portuguese") , however, much of the program was done in Ubuntu. When the other programmer sent me the files and when I am going to compile using mingw32-make to use the makefile, I have problems with the accent, but when compiling using Ubuntu I do not have this problem.

Being the default% C language library, this locale.h should work on both Windows and Ubuntu. Anyone have any idea what the problem is?

    
asked by anonymous 08.02.2016 / 20:45

2 answers

4

This has to do with the file encoding and output encoding of your program.

The problem will not just go away by itself - you need to understand Unicode. I suggest you read This article - the most classic unicode piece I have ever seen, in circulation since 2003 .

This happens because the program locale depends on an internal encoding of the accent (what is the code for the character "ç"?) In the Ubuntu terminal there will be one, in the Windows (cmd) terminal will be another, and in a graphical window in the same Windows will be a third value) - understand Unicode is to know that you need:

  • Normalize all your incoming data, come from the internet, the database, user input, external sensors, etc ... to a single HTML encoding that is used by your working text libraries (UTF -16 and UTF32 are usually used - but if I am not mistaken the gobject system uses utf-8 anyway)
  • Perform all of your processing: comparisons, interpolation, sorting, etc ... with this encoding
  • Encode the text back to the encoding of the target media when it is saved - and nothing forces it to have to be the same encoding for each output - you can output the Windows terminal with an encoding, to the database with another, and still generate an output in HTML with another. (But the most recommended is to configure everything that communicates with your program to use utf-8 - it makes things much easier)
  • 09.02.2016 / 15:38
    2

    In the setLocale function, place the string "" (double quotation marks) as the second parameter, so this may resolve the location according to the location of the OS.

    example:

    setLocale(LC_ALL,"");
    
        
    08.02.2016 / 23:50