|
Tom Liotta wrote:
Minor note (and question for the list)... I haven't actually tried it, but is there any technical reason sprintf() couldn't also be used in ILE RPG?
You could use sprintf(). I assume you're thinking of %x, but %x only works with integers, so you could only do 4 bytes at a time.
Here's one reason not to use sprintf in RPG or anywhere: There's no way to tell sprintf() how long your buffer is, so you just have to make sure it's big enough. Also (this is no big deal), sprintf() adds a null-terminator, so you have to allow a byte for it, and (usually) remove it somehow.
Here's an example of using sprintf to get the hex value of an integer. It displays 0001e240.
H bnddir('QC2LE') D sprintf pr * extproc('sprintf') D buf * value D template * value options(*string) D val 10i 0 value options(*nopass) * I know, buf could be just 9 bytes ... D buf s 100a D hexval s 8a /free sprintf(%addr(buf) : '%8.8x' : 123456); hexval = %str(%addr(buf)); dsply hexval; *inlr = '1';
As an Amazon Associate we earn from qualifying purchases.
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.