// 示例:使用 MultiByteToWideChar 和 WideCharToMultiByte 进行编码转换
#include <windows.h>
#include <stdio.h>
void convertUTF8ToGB2312(const char* utf8Str, char* gb2312Str, size_t gb2312Size) {
// Convert UTF-8 to wide char
int wstrLen = MultiByteToWideChar(CP_UTF8, 0, utf8Str, -1, NULL, 0);
wchar_t* wstr = (wchar_t*)malloc(wstrLen * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, utf8Str, -1, wstr, wstrLen);
// Convert wide char to GB2312
WideCharToMultiByte(CP_ACP, 0, wstr, -1, gb2312Str, gb2312Size, NULL, NULL);
free(wstr);
}
C语言转化编码格式(UTF8转GB2312)
最新推荐文章于 2023-12-22 11:25:36 发布