请问C ,怎么样能把字符输出成 Unicode 代码????

时间:2008-07-24 16:54:24   来源:论坛整理  作者:  编辑:chinaitzhe
请问C ,怎么样能把字符输出成 Unicode 代码????


比如我定义一个 char变量为"我" ,然后用printf输出成 Unicode "/u0000" 这样的编码??

请问这个转换函数应该怎么做呢...

我新手..
网友回复:INT wchar_to_char(WCHAR *_p_wsz_src, CHAR **_pp_sz_out)
{
INT n_src_len = 0;
INT n_out_len = 0;

do
{
if (NULL == _p_wsz_src)
{
break;

} /* End if(); 7/22/2008 [11:07] iidioter */

n_src_len = wcslen(_p_wsz_src) 1;

// WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK,wszSomeString, -1, szANSIString, sizeof(szANSIString), NULL, NULL);
n_out_len = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, _p_wsz_src, -1, NULL, 0, NULL, NULL);

if (NULL != _pp_sz_out)
{
if (NULL != *_pp_sz_out)
{
delete []*_pp_sz_out;

} /* End if(); 7/22/2008 [11:49] iidioter */

*_pp_sz_out = new CHAR[n_out_len 1];

if (NULL == *_pp_sz_out)
{
break;

} /* End if(); 7/22/2008 [12:02] iidioter */

memset(*_pp_sz_out, 0, n_out_len 1);

n_out_len = WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
_p_wsz_src,
-1,
*_pp_sz_out,
n_out_len 1,
NULL,
NULL);

} /* End if(); 7/22/2008 [11:07] iidioter */

} while (0); /* End do while(0); 7/22/2008 [11:07] iidioter */

return n_out_len;
}

网友回复:这两个相互转换的.

C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



INT   char_to_wchar(CHAR *_p_sz_src, WCHAR **_pp_wsz_out)

{

   INT             n_src_len           = 0;

   INT             n_out_len           = 0;



   do

   {

      if (NULL == _p_sz_src)

      {

         break;



      } /* End if(); 7/22/2008   [11:08] iidioter */



      n_src_len = strlen(_p_sz_src);



      n_out_len = MultiByteToWideChar(CP_ACP,0,_p_sz_src, -1, NULL, 0); 



      if (NULL != _pp_wsz_out)

      {

         if (NULL != *_pp_wsz_out)

         {

            delete []*_pp_wsz_out;



         } /* End if(); 7/22/2008   [11:49] iidioter */



         *_pp_wsz_out = new WCHAR[n_out_len   1];



         if (NULL == *_pp_wsz_out)

         {

            break;



         } /* End if(); 7/22/2008   [12:46] iidioter */



         memset(*_pp_wsz_out, 0, (n_out_len   1) * sizeof(WCHAR));



         n_out_len = MultiByteToWideChar(CP_ACP,0,_p_sz_src, -1, *_pp_wsz_out, n_out_len   1); 



      } /* End if(); 7/22/2008   [11:08] iidioter */



   } while (0); /* End do while(0); 7/22/2008   [11:08] iidioter */



   return n_out_len;

}




网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



wchar_t c='ÎÒ';

        wprintf(L"/u%d",c);


网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



wchar_t c='我';

        wprintf(L"/u%d",c);


网友回复:都不好使啊....

网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



wchar_t c=_T("我")


要包含windows.h
网友回复:还是不好使.
关键字:请问,字符,输出,Unicode,代码,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面