Thread: how to print characters of own language?

  1. #1
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71

    how to print characters of own language?

    I am trying to print a message on screen written in my own language(greek).Allthough I use printf like that.

    Code:
     printf("A message in my own language");
    it shows on screen weird characters (like this θεσσάλονικη).

    Maybe it's because those characters belong to the extended ASCII code,but how can i use them?For example. If I try to print the letter K (greek K==english K) with printf a strange char is shown while when i use this
    Code:
     printf("%c",170);
    it shows greek k!

    I also tried to change the font in dos(it has different font than the editor's) but it has only one font and i don't know how to add a new.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You'll need to use unicode functions, most likely. You can prefix an L to indicate a unicode string, which is of type wchar_t*:
    Code:
    L"unicode string"
    Then you use wprintf(), wscanf(), etc.

    Unicode in C: http://evanjones.ca/unicode-in-c.html
    Last edited by dwks; 10-17-2006 at 10:54 AM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You also need a reasonably new compiler which understands say UNICODE and locales, not some 16-bit fossil like TurboC
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Dev-C++ understands unicode, as do most modern compilers: http://bloodshed.net/devcpp.html

    Maybe it's because those characters belong to the extended ASCII code,but how can i use them?For example. If I try to print the letter K (greek K==english K) with printf a strange char is shown while when i use this
    Code:
    printf("%c",170);
    it shows greek k!
    Yes, it's due to the non-portable extended characters. There are only 128 of them, so all the characters you want probably aren't there. To see which ones are there, use an ASCII chart program like the one you posted a while ago to determine the character code for the characters. Then use putchar(number) or something. (You can represent an arbitrary character in a string in octal format with \012, or in hex with \xaa: puts("\011hi\x1b")
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71
    Thanks a lot for your replies! You are really helpful and quick-responding!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. tables...
    By peanut in forum C Programming
    Replies: 21
    Last Post: 10-17-2006, 03:06 PM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  4. Language Script..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-30-2003, 06:48 AM
  5. How do you create and print an array of characters
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 07-09-2002, 04:22 PM