Re: Fixed-Length strings vs. NUL-terminated strings
Chris Hird <chrish-lbwoW8fqX/[email protected]> Fri, 4 Jun 2021 12:26:16 +0000
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <YTOPR0101MB17532288D0E39E29C44C6D72BF3B9@YTOPR0101MB1753.CANPRD01.PROD.OUTLOOK.COM> |
Ooops made a mistake New_string[i] = (read_field[i] == ' ') ? '\0' : read_field[i]; If(read_field[i] == ' ') Sorry. Chris... -----Original Message----- From: C400-L <[email protected]> On Behalf Of Chris Hird Sent: June 4, 2021 8:21 AM To: Bare Metal Programming IBM i (AS/400 and iSeries) <[email protected]> Subject: Re: [C400-L] Fixed-Length strings vs. NUL-terminated strings 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 <[email protected]> On Behalf Of Patrik Schindler Sent: June 4, 2021 8:02 AM To: Bare Metal Programming IBM i (AS/400 and iSeries) <[email protected]> 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: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/c400-l or email: [email protected] 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 -- This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/c400-l or email: [email protected] 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 -- This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/c400-l or email: [email protected] 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