|
On Thu, 18 Apr 2002, James Rich wrote:
>
> I need to convert the following C code to RPG. I suppose I can leave the
> getword() function as C, but I really need to be able to do the main()
> function as RPG. Some help making this RPG would be great :)
>
Not sure if you plan to continue using null-delimited strings in your
RPG version, or what you plan to do... so, I wrote one using RPG's
native VARYING strings (the way you'd normally do variable-length
strings in RPG) rather than the null-terminated stuff you do in C.
Here's sample code:
H DFTACTGRP(*NO)
D getword PR
D word 32766A varying options(*varsize)
D line 32766A varying options(*varsize)
D stop 1A const
D array S 39A varying
D INZ('This is a test. -
D And so is this.')
D string S like(array)
D msg S 52A
D pause S 1A
c eval msg = 'array:' + array
c msg dsply
c dow %len(array) > 0
c callp getword(string: array: ' ')
c eval msg = 'string:' + string
c msg dsply
c enddo
c dsply pause
c eval *inlr = *on
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Get the next word from a line, words are delimited by
* a 'stop' char.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P getword B
D getword PI
D word 32766A varying options(*varsize)
D line 32766A varying options(*varsize)
D stop 1A const
D x S 10I 0
c dow %len(line) > 1
c and %subst(line:1:1) = stop
c eval line = %subst(line:2)
c enddo
c eval x = %scan(stop: line)
c if x > 0
c eval word = %subst(line:1:x-1)
c if x < %len(line)
c eval line = %subst(line:x+1)
c endif
c else
c eval word = line
c eval line = ''
c endif
c return
P E
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.