急求助C语言问题,如何将数组转换成字符串 5
代码如下#defineMAX_UNI_INDEX12constunsignedshortuni_table[][2]={{0x53D1,0xB7A2},/*发:GB231...
代码如下
#define MAX_UNI_INDEX 12
const unsigned short uni_table[][2]={
{0x53D1,0xB7A2}, /* 发: GB2312 Code: 0xB7A2 ==> Row:23 Col:02 */
{0x751F,0xC9FA}, /* 生: GB2312 Code: 0xC9FA ==> Row:41 Col:90 */
{0x706B,0xBBF0}, /* 火: GB2312 Code: 0xBBF0 ==> Row:27 Col:80 */
{0x707E,0xD4D6}, /* 灾: GB2312 Code: 0xD4D6 ==> Row:52 Col:54 */
{0x8FB9,0xB1DF}, /* 边: GB2312 Code: 0xB1DF ==> Row:17 Col:63 */
{0x5883,0xBEB3}, /* 境: GB2312 Code: 0xBEB3 ==> Row:30 Col:19 */
{0x5F02,0xD2EC}, /* 异: GB2312 Code: 0xD2EC ==> Row:50 Col:76 */
{0x5E38,0xB3A3}, /* 常: GB2312 Code: 0xB3A3 ==> Row:19 Col:03 */
{0x540A,0xB5F5}, /* 吊: GB2312 Code: 0xB5F5 ==> Row:21 Col:85 */
{0x91CD,0xD6D8}, /* 重: GB2312 Code: 0xD6D8 ==> Row:54 Col:56 */
{0x8D85,0xB3AC}, /* 超: GB2312 Code: 0xB3AC ==> Row:19 Col:12 */
{0x6807,0xB1EA}, /* 标: GB2312 Code: 0xB1EA ==> Row:17 Col:74 */
};
unsigned short Search(const unsigned short x)
{
int i ;
for(i=0;i<=11;i++)
{
if (x == uni_table[i][1])
return uni_table[i][0];
}
return 0;
}
void UniToStr(const unsigned short *gb,unsigned char *str)
{
unsigned short unicode;
while( *gb )
{
if( (*gb >> 8) == 0) //ASCII
*str++ = (*gb & 0xff);
else {
unicode = Search(*gb);
*str ++ = (unicode >> 8) & 0xff;
*str ++ = unicode & 0xff;
}
gb++;
}
*str ++ = '\0';
}
但是转换出来是乱码,求大神知道啊 展开
#define MAX_UNI_INDEX 12
const unsigned short uni_table[][2]={
{0x53D1,0xB7A2}, /* 发: GB2312 Code: 0xB7A2 ==> Row:23 Col:02 */
{0x751F,0xC9FA}, /* 生: GB2312 Code: 0xC9FA ==> Row:41 Col:90 */
{0x706B,0xBBF0}, /* 火: GB2312 Code: 0xBBF0 ==> Row:27 Col:80 */
{0x707E,0xD4D6}, /* 灾: GB2312 Code: 0xD4D6 ==> Row:52 Col:54 */
{0x8FB9,0xB1DF}, /* 边: GB2312 Code: 0xB1DF ==> Row:17 Col:63 */
{0x5883,0xBEB3}, /* 境: GB2312 Code: 0xBEB3 ==> Row:30 Col:19 */
{0x5F02,0xD2EC}, /* 异: GB2312 Code: 0xD2EC ==> Row:50 Col:76 */
{0x5E38,0xB3A3}, /* 常: GB2312 Code: 0xB3A3 ==> Row:19 Col:03 */
{0x540A,0xB5F5}, /* 吊: GB2312 Code: 0xB5F5 ==> Row:21 Col:85 */
{0x91CD,0xD6D8}, /* 重: GB2312 Code: 0xD6D8 ==> Row:54 Col:56 */
{0x8D85,0xB3AC}, /* 超: GB2312 Code: 0xB3AC ==> Row:19 Col:12 */
{0x6807,0xB1EA}, /* 标: GB2312 Code: 0xB1EA ==> Row:17 Col:74 */
};
unsigned short Search(const unsigned short x)
{
int i ;
for(i=0;i<=11;i++)
{
if (x == uni_table[i][1])
return uni_table[i][0];
}
return 0;
}
void UniToStr(const unsigned short *gb,unsigned char *str)
{
unsigned short unicode;
while( *gb )
{
if( (*gb >> 8) == 0) //ASCII
*str++ = (*gb & 0xff);
else {
unicode = Search(*gb);
*str ++ = (unicode >> 8) & 0xff;
*str ++ = unicode & 0xff;
}
gb++;
}
*str ++ = '\0';
}
但是转换出来是乱码,求大神知道啊 展开
3个回答
展开全部
为什么要用二元数组呢,我新手,提个问,问什么不用一元,也一样呢
追问
因为我要实现国标码和unicode码互相查
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
同样求解
追问
我已经想出来了十六进制数例如0xEDF2,取出其中的每一位,如果是数字就+48,如果是字母就+55,然后就变成ASCII码里面对应的数字或者字母,然后用字符串形式输出就行了
追答
谢谢啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询