免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1798 | 回复: 2
打印 上一主题 下一主题

[故障求助] 码制转换问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-23 10:13 |只看该作者 |倒序浏览
因业务需要,需要把HP机器上的文本(ASCII码形式,对应iso81) 转化成AIX机器上的文本 ebcd码。
函数据说是用convert(tocode, fromcode, Input)
请问:函数中的Input---- 指iint 型的nput file descriptor,输入文件描述符。这是啥东东,百思不得其解。
那位高手能给俺个转换程序参考一下,呵呵,感谢。下面这个编译不过去,偶准备推倒重来,叹息。
#include <iconv.h>;
#include <errno.h>;
char str[1000],strout[1000];
      void main()
      {
        int fd=1;
      ...
         printf("fopen file succ,put str....\n";
         getchar();
         gets(str);
        convert('iso81','engle', fd);
        ......
      }
    int convert(tocode, fromcode, Input)
      {
      /*char *tocode;                        tocode name */
     /* char *fromcode;                       fromcode name */
    /*  int Input;                           input file descriptor */
          extern void error();            /* local error message */
          iconv_t cd;                     /* conversion descriptor */
          unsigned char *table;           /* ptr to translation table */
          int bytesread;                  /* num bytes read into input buffer */
          unsigned char inbuf[BUFSIZ];    /* input buffer */
          unsigned char *inchar;          /* ptr to input character */
          int inbytesleft;                /* num bytes left in input buffer */
          unsigned char outbuf[BUFSIZ];   /* output buffer */
          unsigned char *outchar;         /* ptr to output character */
          int outbytesleft;               /* num bytes left in output buffer */
          size_t ret_val;                 /* number of conversions */

          /* 初始化转换,获得转换描述符 */
          if ((cd = iconv_open(tocode, fromcode)) == (iconv_t)-1)
             {
              /*error(FATAL, BAD_OPEN);*/
              printf("not that code \n";
  }
          inbytesleft = 0;                        /* no. of bytes converted */
          /* translate the characters */
          for ( ;; )
             {
                      inchar =str;          /* points to input buffer */
                      outchar =strout;        /* points to output buffer */
                      outbytesleft = BUFSIZ;   /* no of bytes to be converted */
                      if ((bytesread = read(Input, inbuf+inbytesleft,
                                            (size_t)BUFSIZ-inbytesleft)) < 0)
                           {
                              perror("prog";
                              return BAD;
                           printf("read input file error \n";
                           }
                      if (!(inbytesleft += bytesread))
                           {
                              break;           /* end of conversions */
                            }

                      ret_val = iconv(cd, &inchar, &inbytesleft,
                                      &outchar, &outbytesleft);

  if (write(1, outbuf, (size_t)BUFSIZ-outbytesleft) < 0)
                          {
                              perror("prog";
                              return  BAD;
                           printf(" write out file error \n";
                          }

        if ((ret_val == -1) && (errno == EINVAL))
                         {
                              memcpy((char *)inbuf, (char *)inchar,
                                     (size_t)inbytesleft);
                           printf("error 1 \n";
                         }
          else if ((ret_val == -1) && (errno == EILSEQ))
                         {
/*                             error(FATAL, BAD_CONVERSION);*/
                           printf("error 2 \n";
                         }
          else if ((ret_val == -1) && (errno == E2BIG))
                        {
                              memcpy((char *)inbuf, (char *)inchar,
                                     (size_t)inbytesleft);

       (size_t)inbytesleft);
                              printf("error 3 \n";
                         }
                      /* Go back and read from the input file. */

          /* end conversion & get rid of the conversion table */
   /*    if (iconv_close(cd) == BAD)
                           printf(" close error end \n";*/
              return (0);
          }
     }

论坛徽章:
0
2 [报告]
发表于 2005-05-23 11:49 |只看该作者

码制转换问题

把编译信息贴上来啊。

论坛徽章:
0
3 [报告]
发表于 2005-06-04 16:42 |只看该作者

码制转换问题

"函数中的Input---- 指iint 型的nput file descriptor,输入文件描述符"--就是文件句柄,open(fopen)打开文件的返回值
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP