當前位置:首頁 » 操作系統 » 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。不過對於這個函數來說,在哪個平台上都不會因為字元編碼而影響使用。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:600
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:892
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:585
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:769
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:689
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1016
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:261
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:119
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:809
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:718