Conversion from a wide char to a single char is easy, a wide char is a signed word. So you could just write your own conversion process easy. This means that a the value of 'A' in a single char is the same in wide char. All you have to do is just cast a char to wide char.
So you're trying to write a routine that takes a wide char string and flattens it into a single char eh?
Now if the routine was doing the conversion the other way around then it would be quite dangerous, lol. Btw, to use this routine your making, you'll have mandatorily cast your input string.
Try this(Be sure to use a different pointers for each type so you increment the pointer properly):
CODE
char* ChazWcharToChar(wchar_t* wstr) {
char* cstr = (char*)wstr, *ostr = cstr;
while (1)
{
if (*wstr == 0)
break;
*cstr = *wstr;
++cstr;
++wstr;
}
return ostr;
}
Try that, by the way it isn't completely safe, just rough code.
A word of warning, I just tried to correct what you tried to do, please don't use this routine on initialized data like this:
CODE
wchar_t* str = L"HAHAH";
ChazWcharToChar(str);
This will not work and will cause an access violation because str string points to your program's read only data.
This post has been edited by ChazZeromus: 9 Aug, 2008 - 09:20 PM