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

熱點內容
sql網校 發布:2025-03-20 06:16:42 瀏覽:279
安卓手機圖標排列為什麼會混亂 發布:2025-03-20 06:16:05 瀏覽:760
手機pin初始密碼是多少 發布:2025-03-20 06:15:59 瀏覽:899
javaif常量變數 發布:2025-03-20 06:15:57 瀏覽:343
iis安裝sql 發布:2025-03-20 06:05:31 瀏覽:148
製作自解壓安裝 發布:2025-03-20 05:41:49 瀏覽:304
華為連接電視密碼是多少 發布:2025-03-20 05:31:11 瀏覽:493
演算法第五版 發布:2025-03-20 05:17:57 瀏覽:730
湖南台訪問 發布:2025-03-20 05:10:32 瀏覽:38
腳本和秒搶 發布:2025-03-20 05:06:29 瀏覽:592