I need to use the string that I get from a file or user input with the GUI components of the Irrlicht engine, but I cann't figure it out on how to do it yet.
This is the example of what I want to do.
{...
char name[40];
IGUIListBox* listbox;
...
FILE *fp;
fopen(fp,filename,"rt");
if(fp!=NULL)
{
fscanf(fp,"%s",name);
listbox->addItem(name);
....
}
I also need to get the string from the listbox back to my normal char[] string too.
It seems that the types do not match and I have to convert the variable, but I don't know how,so anyone can helpme out? Please. Thank you.
How to convert between Irrlicht-string to c string
I've looked at the IGUIListBox header file, and it uses Windows-like wide char arrays.
These are 16 bit ints instead of 8-bit ints. They also probably use UCS-16 encoding.
Provided that only English characters are used, you can just copy using something like:
unsigned char mystring[]="Hello world";
unsigned wchar_t[BIGBUFFER] listboxentry; // I'm sure you know how to allocate on the fly if necessary
for(i=0;mystring;i++)
listboxentry=(unsigned wchar_t)mystring;
listboxentry=0;
And back in the same way.
If the encoding is different, it's not a lot of fun. You might need to use UTF-8 if it's for filenames.
Useful links:
http://www.joelonsoftware.com/articles/Unicode.html
http://www.unicode.org/
These are 16 bit ints instead of 8-bit ints. They also probably use UCS-16 encoding.
Provided that only English characters are used, you can just copy using something like:
unsigned char mystring[]="Hello world";
unsigned wchar_t[BIGBUFFER] listboxentry; // I'm sure you know how to allocate on the fly if necessary
for(i=0;mystring;i++)
listboxentry=(unsigned wchar_t)mystring;
listboxentry=0;
And back in the same way.
If the encoding is different, it's not a lot of fun. You might need to use UTF-8 if it's for filenames.
Useful links:
http://www.joelonsoftware.com/articles/Unicode.html
http://www.unicode.org/