當前位置:首頁 » 操作系統 » linuxunicode

linuxunicode

發布時間: 2023-07-03 05:15:13

1. 請求在linux下C語言如何將漢字轉換成UTF

試試這個四個函數,C 裡面的,Linux 可用:
mbtowc
wctomb
mbstowcs
wcstombs
在 Linux 下試試看吧:
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
size_t cch;
char psz[1024];
wchar_t pwsz[] = { 0x52B3, 0x788C, 0x788C, 0 };
setlocale(LC_ALL, "");
cch = wcstombs(psz, pwsz, 1024);
if (cch != 0 && cch != -1) {
printf("%s", psz);
}
return 0;
}
zdl_361 說的 "utf8 勞碌碌" 不對,因為我也輸出 "勞碌碌",而我是用 Unicode 編碼的。在 Windows 上,char 是 ANSI,Unicode (wchar_t) 是 UTF-16;在 Linux 上,char 是 UTF-8,Unicode (wchar_t) 是 UTF-32。不過對於這個函數來說,在哪個平台上都不會因為字元編碼而影響使用。

熱點內容
androidexcel 發布:2025-03-20 08:19:49 瀏覽:634
國外ftp伺服器 發布:2025-03-20 08:19:09 瀏覽:520
linuxftp伺服器搭建設置用戶許可權 發布:2025-03-20 08:19:08 瀏覽:766
域名訪問升級迅雷 發布:2025-03-20 08:01:47 瀏覽:336
安卓開發python 發布:2025-03-20 07:57:30 瀏覽:688
手機代理伺服器怎麼設置限制 發布:2025-03-20 07:51:03 瀏覽:426
keil的c51編譯器 發布:2025-03-20 07:40:46 瀏覽:338
vpn韓國伺服器地址 發布:2025-03-20 07:12:44 瀏覽:28
打碼軟體源碼 發布:2025-03-20 07:08:06 瀏覽:118
前端android 發布:2025-03-20 06:50:42 瀏覽:100