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

熱點內容
電腦配置低怎麼變得不卡 發布:2025-07-15 05:34:08 瀏覽:844
ios火影忍者手游腳本 發布:2025-07-15 05:31:34 瀏覽:82
iphone支付密碼忘了怎麼辦 發布:2025-07-15 05:30:55 瀏覽:775
c語言打開網頁 發布:2025-07-15 05:21:33 瀏覽:640
如何製作我的世界模組伺服器 發布:2025-07-15 05:21:33 瀏覽:903
phparray加 發布:2025-07-15 05:20:41 瀏覽:782
4000以內二手安卓機怎麼選 發布:2025-07-15 05:11:25 瀏覽:644
靜態編譯修復器 發布:2025-07-15 05:11:24 瀏覽:506
iphonexr的存儲空間 發布:2025-07-15 05:09:20 瀏覽:328
能緩存航海王 發布:2025-07-15 04:55:38 瀏覽:91