× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks very much Simon.

My goals for doing this are so that I will become comfortable with C.
Otherwise I'd just do this in RPG!

I figured out that I was incorrectly using STRCPY.

I am intrigued with using embedded sql (not the SQL CLI api's).  Can you
point me to any documentation for doing that in C?  I haven't been able to
find ANY.  I use embedded sql in RPG all the time, and if I can use it
successfully in both C and RPG that would be great.  And I wouldn't have to
figure out how to use _Rlocate (which is what I'm trying to figure out now).

Phil

> -----Original Message-----
> From: c400-l-admin@midrange.com [mailto:c400-l-admin@midrange.com]On
> Behalf Of Simon Coulter
> Sent: Saturday, June 08, 2002 4:03 AM
> To: c400-l@midrange.com
> Subject: Re: [C400-L] packed data
>
>
>
> 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 more
> data than you think because the source data may not have a
> terminating null.
>
> 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 less
> 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.
>
> Regards,
> Simon Coulter.
> --------------------------------------------------------------------
>    FlyByNight Software         AS/400 Technical Specialists
>    http://www.flybynight.com.au/
>
>    Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
>    Fax:   +61 3 9419 0175   mailto: shc@flybynight.com.au   \ /
>                                                              X
>                  ASCII Ribbon campaign against HTML E-Mail  / \
> --------------------------------------------------------------------
>
>








As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.