Hmm, sorry.
You are thinking too hard. ;-] Don't do so much work.
Change all instances of
wchar_t in my function to
unsigned short int and MatLab should stop complaining. (My brain went "Unicode --> wchar_t" instead of what you asked for... :-S )
Then to use it:
1 2 3 4 5 6 7 8
|
const char fileName[] = "C:\\data\\test230.ext";
unsigned short int *fileNameForElementsP;
fileNameForElementsP = ascii_to_unicode( fileName );
thatStupidFunction( fileNameForElementsP );
free( fileNameForElementsP );
|
Don't mix
delete with
malloc(). It is dangerous. Just use
free().
You can't just cast the entire array because the size of the elements don't change. If wchar_t is four bytes long, casting it to unsigned short (two bytes) just means you are treating it as an array of twice as many elements (where every-other one is a null character, since you are splitting the wchar_ts in half).
Nice fix with the size_t!
*sp
is checking to see if the character addressed by
sp is null. It is equivalent to:
*sp != '\0'
*rp = *sp;
exactly. :-)
*rp = 0;
nope. Remember,
rp gets incremented at the same time as
sp, so if
sp is pointing to the null-terminator (a value of zero signals the end of a string), then
rp should also be pointing at a zero. But we exited the loop as soon as we found
sp's zero, so we have to specifically terminate the result string with a zero.
Whew. I hope that made sense.
1./[1 2] --> [1 0.5]
Hmm.. That's cheezy matlab magic, I guess... Cool trick though!