.com                     T
                                                   To:   c400-l@midrange.com
                          Sent by:                 cc:
                          om                       bcc:
                     C400-L digest, Vol 1 #56 - 2

                          06/08/2002 01:00 PM
                          Please respond to

Send C400-L mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of C400-L digest..."

Today's Topics:

   1. Re: packed data (Simon Coulter)
   2. RE: packed data (Bob Crothers)


Message: 1
Date: Sat, 08 Jun 02 18:02:54 +1000
From: "Simon Coulter" <shc@flybynight.com.au>
To: c400-l@midrange.com
Subject: Re: [C400-L] packed data
Reply-To: c400-l@midrange.com

Hello Phil,

You wrote:
>I am moving the characters to the output fields using
>strcpy.  This is when the problem shows up.  The packed
>fields wind up with blanks and all the character fields
>beyond the first packed field are missing 1 character.

C has no concept of fixed-length character fields.  They are simply arrays
of bytes and the C library functions for character strings expect character
values to end with x'00'.  strcpy() appends x'00' to the end of of the
target field.  Without seeing your code I suspect that the terminating null
is overwriting the first byte of each field or you are possibly copying
data than you think because the source data may not have a terminating

Since you are dealing with fixed-length fields you must accept the
responsibility for handling the lengths.  The compiler will not help you at
all.  Use memcpy() and specify the number of bytes to copy.  You could also
possibly use strncpy() if you know that the length you actually copy is
than or equal to the length of the source string.

I am not sure why the packed decimal fields are blank (I presume x'40') but
it may be a side-effect of how you are copying the data.

If that doesn't help then append a sample of your code and a copy of the
input data and output data in text and hex format so we can see what the
code is doing.

Does the input data map directly to the output data except that the output
data is formatted as separate fields?  I mean could you use CPYF
FMTOPT(*NOCHK)?  Or do you need to map differnt parts of the input data?

C is fine for bits and bytes but it sucks for database work -- you might
want to consider embedded SQL or the SQL CLI instead.

Simon Coulter.
   FlyByNight Software         AS/400 Technical Specialists

   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175   mailto: shc@flybynight.com.au   \ /
                 ASCII Ribbon campaign against HTML E-Mail  / \


Message: 2
From: "Bob Crothers" <bob@CStoneIndy.com>
To: <c400-l@midrange.com>
Subject: RE: [C400-L] packed data
Date: Sat, 8 Jun 2002 10:09:28 -0500
Reply-To: c400-l@midrange.com


Amen!  Couldn't say it better myself!
>>C is fine for bits and bytes but it sucks for database work -- you might
>>want to consider embedded SQL or the SQL CLI instead.


This is the C programming iSeries / AS400 (C400-L) digest list
To post a message email: C400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/c400-l
or email: C400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

End of C400-L Digest

This thread ...

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].