Page 1 of 1

wchar_t from char conversion problem

Posted: Mon Aug 23, 2004 5:04 pm
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 ??

Posted: Mon Aug 23, 2004 5:59 pm
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;) )

Posted: Mon Aug 23, 2004 6:17 pm
by Robomaniac
swprintf

Posted: Wed Aug 25, 2004 9:32 am
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?

Posted: Thu Aug 26, 2004 9:31 pm
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.

Posted: Thu Sep 02, 2004 12:05 am
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

Posted: Thu Sep 02, 2004 9:11 am
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: