Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greek letters in Windows Concole

I'm writting a program in C and I want to have Greek characters in the menu when I run it in cmd.exe . Someone said that in order to include Greek characters you have to use a printf that goes something like this:

 printf(charset:IS0-1089:uffe);      

but they weren't sure.

Does anyone know how to do that?

like image 398
system Avatar asked Oct 11 '22 21:10

system


1 Answers

Assuming Windows, you can:

  • set your console font to a Unicode TrueType font:
  • emit the data using an "ANSI" mechanism

This code prints γειά σου:

#include "windows.h"

int main() {
  SetConsoleOutputCP(1253); //"ANSI" Greek
  printf("\xE3\xE5\xE9\xDC \xF3\xEF\xF5");
  return 0;
}

The hex codes represent γειά σου when encoded as windows-1253. If you use an editor that saves data as windows-1253, you can use literals instead. An alternative would be to use either OEM 737 (that really is a DOS encoding) or use Unicode.

I used SetConsoleOutputCP to set the console code page, but you could type the command chcp 1253 prior to running the program instead.

like image 154
McDowell Avatar answered Oct 31 '22 13:10

McDowell