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 😊
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
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. ;-)
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,
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
As an Amazon Associate we earn from qualifying purchases.