user2571032
user2571032

Reputation: 131

Getting a Dev-C++ built program to output UNICODE characters to the Windows command line

If you can answer any of my questions, that would be awesome.

Here's the scoop: I'm teaching an intro to programming class in Thailand to 11th graders. It's been going great so far, their level of English is high enough that I can teach in English and have them write programs in English and everything is fine and dandy.

However, as speakers of a language with non-Latin characters, I feel that they should at least learn what UNICODE is. I won't test them on it or bog them down with implementation details, but I want to show them an example of a UNICODE program that can do I/O with Thai characters.

I'm operating under the following constraints, none of which can be changed (at least for this semester):

Here's how far I've gotten, and the questions I have:

I'd love to end this course with a program that outputs สวัสดีโลก, the Thai equivalent of "Hello World!" I've done tons of googling, but every answer I've found either doesn't work in this specific case or involved a different IDE.

Upvotes: 4

Views: 10903

Answers (3)

pablo1977
pablo1977

Reputation: 4433

If you need to change the code page in a console C program, you can add the header <stdlib.h> and the line system("CHCP 874"); at the beginning of the program.

If you need a free compiler conforming with C99 under windows, you can try Pelles C:

http://www.christian-heffner.de/index.php?page=download&lang=en

It is conforming at all with C99.

You have to use wide-string constants, that have the following syntax:

L"Wide string\n"

Instead of printf(), you need to use wprintf() and the like.

http://pubs.opengroup.org/onlinepubs/7908799/xsh/wchar.h.html

Upvotes: 0

user2527098
user2527098

Reputation:

Ok, here's my bit of help. I don't use Dev-C++ as my IDE, so I can't help you with IDE specific things, but the following is standard to most C/C++ compilers:

wprintf is the printf implementation for wide characters (unicode).

When using wide characters you will use wchar_t in place of char for defining strings.

so you might do something like this

#include <wchar.h>

int main(int argc, char** argv) {
    wchar_t* str = L"สวัสดีโลก";
    wprintf(L"%s", str);
    system("pause");
    return 0;
}

wprintf is most likely what you're looking for.

Other functions for printing and manipulating wide strings can be found by researching the wchar.h header file.

Reference: wprintf - C++ Reference

Using L before the quotations means you intend to define a wide string. (unicode)

Hope that helps,

-Dave

Upvotes: 1

Ahmed Masud
Ahmed Masud

Reputation: 22402

I have never used DEV-C++ IDE :-) However, after reading up on it a bit I see that dev-c++ version 4.9.9.3 uses gcc-3.5.4 mingw port. Which has universal character support status of "Done" see http://gcc.gnu.org/gcc-3.4/c99status.html for details. You have to change the IDE configuration such that the compiler uses -std=c99 as part of the compiler flags.

Hopefully that will do the trick.

I will try to fiddle with it on my own system and see how far we can get. Will update the answer if I find more clues :-)

Upvotes: 0

Related Questions