Hi.
A few days ago I downloaded Irrlicht and successfully compiled it in VC 6.0 While I am still discovering Irrlicht in general, I have already begun to program a 3D game editor with Irrlicht, a tool that would save me resources and time, and basically beats the need to compile everything all the time. Sadly I mostly work on PERL projects (CGI, etc) elsewhere, and my C++ skills are not as sharp as they should be.
Allright, here goes the question. I have this piece of code:
----------------------------------
wchar_t svdScreenMessage[1024];
char abc[1024] = "TEXT MESSAGE 5";
// Some other stuff ...
swprintf(svdScreenMessage, 1024, L"%s", abc);
guienv->addStaticText(svdScreenMessage, true, rect<int>(10,50,200,70));
---------------------------
All right. Basically what I am trying to do here is to copy the abc string (declared with char) into svdScreenMessage (declared with wchar_t as provided by IrrLicht). It turns out that it actualy compiles, with no errors. However, when I run the program,instead of seeing "TEXT MESSAGE 5" I just see some odd symbols like |||||
The only reason I want to do this is because I wanted to create a dinamic text box that would inform me of things during the game, and thus I wanted to use functions such as strcpy and strcat, etc, which wchar_t wont accept.
Is there any way to copy a normal string declared with char to a string declared with wchar_t ????
Thanks.
-IrrLicht Newbie
Problems with a string
Hi,
Yeah, you try to copy a singlebyte string into a Unicode string. Compiles fine, because swprintf simply takes the next pointer on the stack, whatever that is, and, seeing %s, tries to interpret it as a pointer to a zero-terminated Unicode string.
Simple solution 1:
use mbtowc() to convert your abc string to Unicode before using it.
Even simpler solution 2:
you could declare your abc string tobe unicode right away:
wchar_t abc [] = L"TEXT MESSAGE";
Question to other people: I'm pretty sure that gcc catches those errors, because I have seen it parsing the printf format string when compiling and warning me about wrong arguments. Does anyone know whether VC++ can do the same?
...thomas
Yeah, you try to copy a singlebyte string into a Unicode string. Compiles fine, because swprintf simply takes the next pointer on the stack, whatever that is, and, seeing %s, tries to interpret it as a pointer to a zero-terminated Unicode string.
Simple solution 1:
use mbtowc() to convert your abc string to Unicode before using it.
Even simpler solution 2:
you could declare your abc string tobe unicode right away:
wchar_t abc [] = L"TEXT MESSAGE";
Question to other people: I'm pretty sure that gcc catches those errors, because I have seen it parsing the printf format string when compiling and warning me about wrong arguments. Does anyone know whether VC++ can do the same?
...thomas
swprintf() expects you to send it wchar_t for "%S" thats why you got "|||"
you're going to need to convert your char to wchar_t before sending to swprintf()
there is a function, whos name I forget, something like "wstochar" and "chartows" which does conversion between the two.
you're going to need to convert your char to wchar_t before sending to swprintf()
there is a function, whos name I forget, something like "wstochar" and "chartows" which does conversion between the two.
a screen cap is worth 0x100000 DWORDS
check out this thread http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=906... i love my dout's