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



Use a for() loop from position n to start of field until a non space is found.

Eg:

Field read is 120 bytes with blanks added to end of field.
For(i = 119; i > 0; i--) {
New_string[i] = (read_field[i] != ' ') ? '\0' : read_field[i];
If(read_field[i] != ' ')
break;
}

If the field is NULL terminated when written then this would not be necessary, just use strcpy(new_field,read_field);

There are no API's or anything else to look for the length of a character array to a string automatically, you can using the above come up with one of your own.
Another option would be to have a separate field that stores the string length when written.

Chris...

-----Original Message-----
From: C400-L <c400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Patrik Schindler
Sent: June 4, 2021 8:02 AM
To: Bare Metal Programming IBM i (AS/400 and iSeries) <c400-l@xxxxxxxxxxxxxxxxxx>
Subject: [C400-L] Fixed-Length strings vs. NUL-terminated strings

Hello,

reading from a database table (declared with fixed length strings for easier handling in RPG for green screen use) with the _R API calls returns fixed length strings, filled with spaces until the space is exhausted.

Do I need to come up with a hand crafted function to "convert" these to C-style strings, or does IBM i provide an API for achieving this? By "conversion" I want to point out that I don't care if that function just places a NUL on the proper position's original buffer, or the string gets just copied and the copy is treated accordingly.

My Google searches yield a lot of unrelated information, because the question seems rather generic. The IBM API finder list yielded no usable results by searches for string, fixed or NUL.

Thanks for your hints!

:wq! PoC

--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxxxxxxxx Before posting, please take a moment to review the archives at https://archive.midrange.com/c400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

As an Amazon Associate we earn from qualifying purchases.

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