Re: Fixed-Length strings vs. NUL-terminated strings
Patrik Schindler <[email protected]> Fri, 4 Jun 2021 15:11:30 +0200
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <[email protected]> |
Hello Chris, Am 04.06.2021 um 14:42 schrieb Chris Hird <[email protected]>: > You will be surprised how quick it really is and how little CPU it takes to do this. Indeed! > 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. Yes, I guessed that. I'm just reluctant to reinvent the wheel. > 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. Yap. I'm also prone to this and other kinds of off-by-one-errors. > 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. I have some experience with C on Linux, but apparently, years of doing RPG, a little perl and shell scripts allowed some rust on my C skills. :-) Thanks for your help, again. > RPG offers no benefits to me 😊 Run, duck and cover! Okay, maybe not in this group. ;-) I could have done that task in (positional) RPG, also. But since I need a considerable amount of static strings for all the HTML table surroundings, I expected that to be cumbersome. And so this was a perfect "excuse" to learn something half-new. As with a cooked meal, wrong — or missing — ingredients make the taste fail. ;-) :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