Print special characters on windows console

Asked

Viewed 3,335 times

3

How to print special characters like 'is' and 'ç' on the windows console (printf)?

2 answers

3

As you can find on the site: http://linguagensdeprogramacao.wordpress.com/2011/07/16/resolvendo-problema-da-acentuacao-no-dev-c/

To solve this problem just use the command of C regionalization so that not only accentuate the words correctly, but showing dates and times in Portuguese, for example.

This is done using the locale library setlocale command.h. Follow an example of code.

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

int main(void)
{
    setlocale(LC_ALL, "Portuguese");
    printf("Alô mundo! \n\n");

    system("PAUSE");
    return 0;
}

----- Edit --------

If you still have problems try to change the Command source:

Command

  • 2

    Thanks, but I’ll take the other one for having more details.

2


There are three ways to use these special characters in windows :

  1. Swiping the code right into the printf: printf("isto \x82"); //imprime isto é

    (This code above assumes the Codepage 850 )

  2. Creating a function that uses the above functionality to print the special characters an example the function oprintf who is available with the LGPL license

  3. Or as Giovani said, using setlocale.

Note: I suggest not using system("PAUSE"); nor the library when there is no need. (They are in the setlocale example).

  • 1

    And what page code are you taking into account? x82 is not "is" in all Cps

  • 850, which seems to me to be one of the most common.

  • Perhaps it would be good to complement the answer warning this, because you can not count on the CP always be the "common", even if this statement was true.

  • 1

    And anyway, what is common here may not be common internationally.

  • @Bacco updated the answer to specify this.

  • @mgibsonbr, my old computer used Windows in Danish, my current computer is Windows in English (Canada). And in the computer I have access (remote) in the college of Brazil coincidentally use the same codepage. I agree that it is not universal, but it seems to me that it works for most cases.

Show 1 more comment

Browser other questions tagged

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