#1
by ぷぷぷジューシー » 4年前
url解析機を作っていてワイド文字に変換した方がアジア系の言語が扱えると聞いたのでマルチバイトを一時的にワイド文字に変換して操作した結果をマルチバイトに変換するという機能です
しかしuchar.hライブラリーを試しに使って引っ掛かりましたそれはprintfで出力してもwしか出力しません。
"wwゴリラハローC言語を丸々を出力するにはどうすればいいのでしょうか
環境は os :windows 10, cコンパイラー: MinGW-W64(8.1.0), ライブラリ: uchar.h, stdio.h, limits.h, stdlib.h
現在参考にしているリンク先
https://www.ibm.com/support/knowledgece ... m#mbrtoc32
https://www.ibm.com/support/knowledgece ... 2rtomb.htm
*下のコードが質問に該当するコード
コード:
#include <stdio.h>
#include <stdlib.h>
#include <uchar.h>
#include <limits.h>
int main(void)
{
char input[] = "wwゴリラハローC言語";
char output[MB_LEN_MAX+1];
char32_t inp32b;
size_t mbfuncerror;
mbfuncerror = mbrtoc32(&inp32b, input, (int)(MB_LEN_MAX + 1), NULL);
if (mbfuncerror < 0){
printf("変換に失敗しました mbrtoc32()\n");
printf("エラーコード%d\n", mbfuncerror);
}
printf("%d\n",mbfuncerror);
mbfuncerror = c32rtomb(output, inp32b, NULL);
if (mbfuncerror < 0){
printf("変換に失敗しました c32rtomb()\n");
printf("エラーコード%d\n", mbfuncerror);
}
output[(int)(sizeof(output))] = '\0';
printf("%s\n", output);
}
url解析機を作っていてワイド文字に変換した方がアジア系の言語が扱えると聞いたのでマルチバイトを一時的にワイド文字に変換して操作した結果をマルチバイトに変換するという機能です
しかしuchar.hライブラリーを試しに使って引っ掛かりましたそれはprintfで出力してもwしか出力しません。
"wwゴリラハローC言語を丸々を出力するにはどうすればいいのでしょうか
環境は os :windows 10, cコンパイラー: MinGW-W64(8.1.0), ライブラリ: uchar.h, stdio.h, limits.h, stdlib.h
現在参考にしているリンク先[url]https://www.ibm.com/support/knowledgecenter/ja/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/mbrtoc32.htm#mbrtoc32[/url]
[url]https://www.ibm.com/support/knowledgecenter/ja/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/c32rtomb.htm[/url]
*下のコードが質問に該当するコード
[code]
#include <stdio.h>
#include <stdlib.h>
#include <uchar.h>
#include <limits.h>
int main(void)
{
char input[] = "wwゴリラハローC言語";
char output[MB_LEN_MAX+1];
char32_t inp32b;
size_t mbfuncerror;
mbfuncerror = mbrtoc32(&inp32b, input, (int)(MB_LEN_MAX + 1), NULL);
if (mbfuncerror < 0){
printf("変換に失敗しました mbrtoc32()\n");
printf("エラーコード%d\n", mbfuncerror);
}
printf("%d\n",mbfuncerror);
mbfuncerror = c32rtomb(output, inp32b, NULL);
if (mbfuncerror < 0){
printf("変換に失敗しました c32rtomb()\n");
printf("エラーコード%d\n", mbfuncerror);
}
output[(int)(sizeof(output))] = '\0';
printf("%s\n", output);
}
[/code]