Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1083755
  • 博文数量: 646
  • 博客积分: 288
  • 博客等级: 二等列兵
  • 技术积分: 5375
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-08 14:33
个人简介

为了技术,我不会停下学习的脚步,我相信我还能走二十年。

文章分类

全部博文(646)

文章存档

2014年(8)

2013年(134)

2012年(504)

分类: LINUX

2013-02-25 09:18:39

原文地址:linux下utf8转gbk C语言实现 作者:andyhzw

#include
#include
#include

main()
{
     int cd;
    
     unsigned char utf_8[10]="中";  
     unsigned char gb[10]={0};  
     unsigned char *pi1    =  utf_8;
     unsigned char **pi2    =  &pi1;
     unsigned char *po1    =  gb;
     unsigned char **po2    =  &po1;
     size_t           ilen        = 3;
     size_t           olen    = 2;
    
     iconv_t conveter;

    if((conveter = iconv_open("gbk", "utf-8")) == (iconv_t)-1)
    {

        printf("iconv open fail \n");
        return 1;
    }
    else
    {
        printf("iconv open ok \n");    
    }
    
    iconv(conveter,(char**)pi2,&ilen,(char**)po2,&olen);

 
     printf("\r\n utf_8[0] = %x \r\n",utf_8[0]);
     printf("\r\n utf_8[1] = %x \r\n",utf_8[1]);
     printf("\r\n utf_8[2] = %x \r\n",utf_8[2]);

     printf("\r\n gb[0] = %x \r\n",gb[0]);
     printf("\r\n gb[1] = %x \r\n",gb[1]);

}


阅读(823) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~