char_to_wchar 字符编码

static int char_to_wchar(const char* orig_str, wchar_t *wtext, int max_length)
{
int nCoverLen = 0;
//add by shenbo
setlocale(LC_ALL, "zh_CN.utf8");
nCoverLen = mbstowcs(wtext, orig_str, max_length - 1); 
      
if(-1 == nCoverLen){  
       perror("mbstowcs");
        return -1;
}  
     if(wcscat(wtext, L"") == NULL) {
perror("wcscat");
return -1;
}
return nCoverLen;
}


if(char_to_wchar(optarg,stream_text_info[stream_id].textbox[area_id].content, sizeof(stream_text_info[stream_id].textbox[area_id].content)) < 0)
{
printf("Convert to wchar failed. Use default string.\n");
memset(stream_text_info[stream_id].textbox[area_id].content, 0,
sizeof(stream_text_info[stream_id].textbox[area_id].content));
}

wchar_t //字符编码

你可能感兴趣的:(char)