The conversion descriptor is reuseable.  I would check to make sure you 
aren't inadvertently writing over it somewhere in your code (like you seem 
to be assuming your input will never exceed 32K but don't actually check).

Bruce Vining
 



Davis Yokana <dyokana@xxxxxxxxxxx> 
Sent by: c400-l-bounces+bvining=us.ibm.com@xxxxxxxxxxxx
04/07/2006 02:12 PM
Please respond to
C programming iSeries / AS400 <c400-l@xxxxxxxxxxxx>


To
C programming iSeries / AS400 <c400-l@xxxxxxxxxxxx>
cc

Subject
Re: [C400-L] problems with iconv_open






Thank everyone for their help.

Is the iconv_t cd object reusable? When I repeatedly call 

int rc = iconv(cd, &pRecord,&inBytesLeft,&pAsciiBuffer,&outBytesLeft); 

I get a message to the effect that the descriptor is bad. Does one have
to create a new iconv_t object for each call to iconv()?

On Fri, 2006-04-07 at 12:20 -0500, Scott Klement wrote:
> > which is the text associated with errno. This is V5R2. I am trying to 
do 
> > ebcdic to ascii translation. I would much appreciate any ideas anyone 
> > might have.
> 
> I prefer to use QtqIconvOpen(), I find that it's a little nicer than 
> iconv_open().  Here's a sample of translating EBCDIC -> ASCII using that 

> technique:
> 
> #include <qtqiconv.h>
> #include <iconv.h>
> #include <string.h>
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> #define OUTBUFSIZE 32768
> 
> int main(int argc, char **argv) {
> 
>      QtqCode_T from, to;
>      iconv_t ic;
>      size_t insize, outleft;
>      char outbuf[OUTBUFSIZE];
>      char *inptr, *outptr;
> 
>      memset(&from, 0, sizeof(from));
>      memset(&to, 0, sizeof(to));
> 
>      from.CCSID = 0;     // current job's EBCDIC
>      to.CCSID   = 819;   // ISO 8859-1 ASCII
> 
>      ic = QtqIconvOpen(&to, &from);
>      if (ic.return_value == -1) {
>         fprintf(stderr, "QtqIconvOpen(): %s\n", strerror(errno));
>         exit(1);
>      }
> 
>      insize = strlen(argv[1]);
>      inptr = argv[1];
> 
>      outleft = OUTBUFSIZE;
>      outptr  = &outbuf[0];
> 
>      iconv(ic, &inptr, &insize, &outptr, &outleft);
>      iconv_close(ic);
> 
>      printf("ASCII string = %s\n", outbuf);
>      return 0;
> }
> 

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].