Author Topic: Charset for cmd prompt  (Read 15945 times)

Offline gazzatav

  • Single posting newcomer
  • *
  • Posts: 4
Charset for cmd prompt
« on: January 24, 2009, 10:04:16 pm »
I am creating small beginner programs in windows using console projects.

Which settings should I change to preserve characters from the editor in the windows command prompt.

In particular the english pound sign £ changes to ┬ú.  If I resave the main.cpp file in a dos ide (rhide) after editing the £ changes to œ, it builds fine in CB.

Code::Blocks 8.02
winxp sp3

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Charset for cmd prompt
« Reply #1 on: January 25, 2009, 09:30:51 am »
That's a very annoying issue in Windows, and it's caused by the codepage used by the console (it's different to the one used in the graphical environment).

I'm just checking Code::Blocks' available encodings and I see WINDOWS-1252 (Settings -> Editor: Default encoding when opening files) in its list. Here you can see how to change the codepage of the console to 1252.

In short, you must be sure the codepage used by the console and the one you save your source files in match.

Offline gazzatav

  • Single posting newcomer
  • *
  • Posts: 4
Re: Charset for cmd prompt
« Reply #2 on: January 26, 2009, 01:07:09 am »
Thanks for that reply.  I had tried to go about it in the opposite direction by setting the editor's code page to 950.  This didn't work either so I ended up coding the pound as char pound=0x9c which did work.

After your reply I tried making a system call to the console to change the codepage to 1252 (after setting the editor and file encoding back to 1252).  The console showed that the active codepage had changed but the characters still came out wrong, except for the one coded as 0x9c so I'm still confused as to what I'm doing wrong with the settings - there doesn't seem to be any point changing the codepage in the registry if the console doesn't behave any differently.

By the way if it helps the character that keeps turning up instead of the pound is at 0xa3 on the codepage.
« Last Edit: January 26, 2009, 01:28:58 am by gazzatav »

Offline gazzatav

  • Single posting newcomer
  • *
  • Posts: 4
Re: Charset for cmd prompt
« Reply #3 on: February 01, 2009, 12:22:43 am »
Still can't get this working right.  Tried the internationalization option in settings->environment and restarted.  A codepage choice window appears briefly then Code::Blocks crashes.  Is the en-gb locale available?  Help appreciated.

Offline gazzatav

  • Single posting newcomer
  • *
  • Posts: 4
Re: Charset for cmd prompt
« Reply #4 on: April 27, 2009, 10:13:42 pm »
I still have this problem.  If I set the codepage in editor, program and console to 1252 the English pound gets converted to ú when my test program runs.  If I set the console by chcp to 28591 (8859-1) and type '£', I get 'ú'.  I thought this might be a us/en locale problem but I don't think a us keyboard has 'ú' in the shift position of '3'.  Any help appreciated - the problem definitely is not solved by setting the codepage of the console.  How can I get Code::Blocks to use codepage 850?