Greek letters in Windows Concole

I am writing a C program and I want to have Greek characters in the menu when I run it in cmd.exe. Someone said that to include Greek characters you should use printfone that looks something like this:

 printf(charset:IS0-1089:uffe);      

but they were not sure.

Does anyone know how to do this?

+5
source share
4 answers

Assuming Windows, you can:

  • set the console font to the Unicode TrueType font:
  • emit data using the ANSI mechanism

This code prints γειά σου:

#include "windows.h"

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

γειά σου windows-1253. , windows-1253, . OEM 737 ( DOS-) Unicode.

SetConsoleOutputCP , chcp 1253 .

+4

, , . , , ASCII. #, C.

913 to 936 =

945 968 =

Suite101: #: ASCII # | Suite101.com .

0

unicode char, printf :

printf("\u0220\n");

Ƞ

0

- . , Windows . #if.

#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>

/* This has been reported not to autodetect correctly on tdm-gcc. */
#ifndef MS_STDLIB_BUGS // Allow overriding the autodetection.
#  if ( _WIN32 || _WIN64 )
#    define MS_STDLIB_BUGS 1
#  else
#    define MS_STDLIB_BUGS 0
#  endif
#endif

#if MS_STDLIB_BUGS
#  include <io.h>
#  include <fcntl.h>
#endif

void init_locale(void)
// Does magic so that wprintf() can work.
{
  // Constant for fwide().
  static const int wide_oriented = 1;

#if MS_STDLIB_BUGS
  // Windows needs a little non-standard magic.
  static const char locale_name[] = ".1200";
  _setmode( _fileno(stdout), _O_WTEXT );
#else
  // The correct locale name may vary by OS, e.g., "en_US.utf8".
  static const char locale_name[] = "";
#endif

  setlocale( LC_ALL, locale_name );
  fwide( stdout, wide_oriented );
}

int main(void)
{
  init_locale();
  wprintf(L"μουσάων Ἑλικωνιάδων ἀρχώμεθ᾽\n");
  return EXIT_SUCCESS;
}

UTF-8 , Visual Studio . Unicode, Lucida Console, . ASCII, %ls %lc printf(), Ive , .

UTF-8 ( Windows chcp 65001.), UTF-8 printf(u8"μουσάων Ἑλικωνιάδων ἀρχώμεθ᾽\n");. UTF-8 Windows, . , , .

0

All Articles