× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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 thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.