char* を wchar_t* に変換する関数を実装しようとしています。しかし、問題は、wprintf が異なる結果を示すことです。私は何を間違っていますか?
wchar_t *toWchar(char *data)
{
if(!data)
{
return NULL;
}
int size = strlen(data);
if(!size)
{
return NULL;
}
char *temp = (char *)malloc(size * 2);
if(!temp)
{
return NULL;
}
int j = 0;
for(int i = 0; i < size; i++)
{
temp[j++] = data[i];
temp[j++] = '\0';
}
return (wchar_t *)temp;
}
編集: 主な機能:
int main()
{
wchar_t *temp = toWchar("hello, world!");
if(temp)
wprintf("%ls\n", temp);
return 0;
}