wchar_t from char conversion problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
melon2004
Posts: 13
Joined: Tue Jul 27, 2004 6:53 pm

wchar_t from char conversion problem

Post by melon2004 »

I know this is not realy about Irrlicht - but somehow it's connected because Irrlicht works on wchar_t types. And that couses my problems :(

I try to put text into structure like this:
struct Question
{
wchar_t question[1024];
wchar_t answer1[1024];
wchar_t answer2[1024];
...
};

from text file. It's done like this: (already have Question question[100] struct)

char buffer[1024];
int i =0;

ifstream questionfile ("questions.txt");
while (!questionfile.eof())
{
questionfile.getline (buffer, 100);
sprintf(question.question, 1024, L"Question: %s", buffer);
cout<<buffer<<endl;
...
i++;
}

I mean - this is simple code but I'm not very familiar with wchar_t because it doesnt work :(
I checked and rechecked questions.txt file, even removed it and created again (under windows, before that I had file created under linux). As I remember i worked under Linux.
On this computer I have winXP pro.
Part of code cout<<buffer<<endl; shows text properly on the console.

?? What am I doing wrong ??
melon2004
Posts: 13
Joined: Tue Jul 27, 2004 6:53 pm

Post by melon2004 »

oh, I forgot to mention what the problem is, after all :D

of course, any text taken from text file is not displayed properly in GUI.
Instead I can see... eh, something with very wrong codepage (like trying to display korean utf16 text as ascii iso-8859-2 for example).

please, at least post some links with desent documentation about wchar_t (humanum no-grande-expertum readable;) )
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

swprintf
The Robomaniac
Project Head / Lead Programmer
Centaur Force
melon2004
Posts: 13
Joined: Tue Jul 27, 2004 6:53 pm

Post by melon2004 »

thanks, I'll try it as soon as I switch to win again. Right now debugin under lin, killing bugs :twisted:
text works here OK (?) :roll: without making any changes - is something wrong with utf under win or my code is working here - under X - by accident?
melon2004
Posts: 13
Joined: Tue Jul 27, 2004 6:53 pm

Post by melon2004 »

ehhh, of course I used swprintf originaly - this was just a typing error in my post. So problem remain - but I'm closer to solve it by my self.

Btw. I am VERY confused about swprintf function and it's different mutations.
When I jumped to dev-CPP from Kdevelop, compiler seems to understand and compile what I already have done, but in new added files/classes it only "understand" some non standard (m$?) form (without second int argument). That is probably again my fault of misunderstanding or lack of knowledge, but this time it really looks like compiler is a woman - and can't make her mind what to compile or not.
yin nadie
Posts: 43
Joined: Wed Mar 31, 2004 1:03 pm
Location: Seville, Spain
Contact:

Post by yin nadie »

ow. I just remembered that i was meaning to post this in order to save some coders from the terrible migraine that only Window$ libraries can inflict upon you

oh, well

just write this somewhere:

#ifdef WIN32
#define swprintf _snwprintf
#endif

it has always worked for me
melon2004
Posts: 13
Joined: Tue Jul 27, 2004 6:53 pm

Post by melon2004 »

thanks! that should do.

I couldn't find decend documentation about this type of differences, so I had to... almost guess the solution (with a little help from google and tips in devC++).

Just wonder if there's more catches like that one? :roll:
Post Reply