0

I'm programming in windows, but in my C console some characters (like é, à, ã) are not recognizable. I would like to see how can I make widows interpret those chars as using unicode in the console or utf-8.

I would be glad for some enlightening. Thank you very much

Telmo Vaz
  • 189
  • 1
  • 2
  • 11
  • Strictly speaking, ASCII only defines characters 0 - 127. In this sense, your question is meaningless. – Bathsheba Sep 06 '13 at 13:15
  • Can you show a simple example program or fragment you've tried that doesn't work? – lurker Sep 06 '13 at 13:16
  • Is this relevant (with no code I can't tell)?http://stackoverflow.com/questions/11287213/what-is-a-wide-character-string-in-c-language – doctorlove Sep 06 '13 at 13:17
  • I would guess that cmd.exe uses the same symbol table as good old DOS. Meaning you'll have 7-bit ASCII and then a non-standard "extended ASCII" on top of that, such as the tables in [this link](http://www.asciitable.com/). "Extended ASCII" is not compatible with UTF-8. – Lundin Sep 06 '13 at 13:47
  • @Bathsheba, some people use "ascii" when they really mean "8-bit". My command window uses code page 437 by default, which has many accented characters but in different positions than they are in ISO/IEC-8859-1 (which was used for the first 256 codepoints of Unicode). – Mark Ransom Sep 06 '13 at 22:35

2 Answers2

1

By console do you mean cmd.exe? It doesn't handle Unicode well, but you can get it to display "ANSI" characters by changing the display font to Lucida Console and changing the code page from "OEM" to "ANSI." By the choice of characters you seem to be Western European, so try giving this command before running your application:

chcp 1252

If you want to try your luck with UTF-8 output use chcp 65001 instead.

Joni
  • 108,737
  • 14
  • 143
  • 193
1

Although I completely agree with Joni's answer, I think it can be added a detail:

Since Telmo Vaz asked about how to solve this problem for C programs, we can consider the alternative of adding a system command inside the code:

  #include <stdlib.h>   // To use the function system();
  #include <stdio.h>

  int main(void) {
      system("CHCP 1252");

      printf("Now accents are right: áéíüñÇ  \n");
      return 0;
  }

EDIT It is a good idea to do some experiments with codepages. Check the following table for information (under Windows):

Windows Codepages

pablo1977
  • 4,281
  • 1
  • 15
  • 41
  • Have you checked if this really works? I think `chcp` is a builtin command, not an external program that can be executed through `system`. – Joni Sep 07 '13 at 15:19
  • @Joni This works, I used it thousands of times since I am a Spanish speaker. – pablo1977 Sep 07 '13 at 16:36