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



You will be surprised how quick it really is and how little CPU it takes to do this. Any other language has to resort to the same process under the covers, they have just created functions to do it and called them API's.
The web is just the same if you need to NULL terminate a fixed length field to the last space, the scripting languages just hide the activity from you.

C can bite you hard if you get things wrong with strings etc, I see lots of code where people do a strcpy() to a buffer that is the same length as the string, that means the NULL termination which is always added writes over the next storage, then they write something to that storage and the string is no longer null terminated.

I am sure you will get the hang of it, I never write anything but C on the IBM i now (except where I have to) and I have not stumbled into anything that cannot be achieved and run economically. RPG offers no benefits to me 😊

Chris...


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

Hello Chris,

Am 04.06.2021 um 14:21 schrieb Chris Hird <chrish@xxxxxxxxxxxxxxxxxx>:

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

Thanks! That's what I'll do. But I'm a bit surprised that there seem to be no APIs for that on a Platform IBM has been pushing to be webby. Maybe this knowledge has been lost because today, everything is done with SQL…

Another option would be to have a separate field that stores the string length when written.

Since the original strings are fixed length, I don't see a way to get this fixed other than by looping over the individual fields' buffer, and set the byte immediately next to the first non-space character to NUL. Similar to your proposal. Since the buffer will be overwritten with the following _Rreadn anyway, I'll modify the original buffer. Might also save some CPU cycles on my 150. ;-)

Thanks again!

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