× 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 Tue, 17 Sep 2002 varner@mail.holyname.org wrote:
>
> I need to retrieve the last 32000 characters from a null-terminated string.
> According to IBM this can only be done using a C language program.  I don't
> know C.  Does anyone have any examples or suggestions?
>

There's always a way.   If I understand you correctly, the string is
approx 96k (i.e. 32000 chars past the RPG limit of 65535).

You can do this by allocating space for 96k of data, then using two
variables in RPG.  One that displays the first 65535, which would be
based on a pointer at the start of our 96k area, and then a second
variable to cover the other 32000 bytes, this one will be based on
the area right after the first string ends.

Conceptually, it's just like putting both strings in a data structure.
Except that the compiler will complain about the size if we use a data
structure, so we'll cheat and use pointers.

Here's some sample code:

     D p_bigstring     S               *
     D part1           S          65535A   based(p_bigstring)
     D p_part2         S               *
     D part2           S          32000A   based(p_part2)
     D size            S             10I 0

     D someCproc       PR            10I 0 extproc('somecproc')
     D   data                          *   value

     c                   eval      size = %size(part1) + %size(part2)
     c                   alloc     size          p_bigstring
     c                   eval      p_part2 = p_bigstring + %size(part1)
     c                   eval      part1 = *blanks
     c                   eval      part2 = *blanks

     c                   if        someCproc(p_bigstring) = 0
     C***  it worked
     c                   else
     C***  it didn't
     c                   endif

      *** get rid of allocated memory when we're done with it:
     c                   dealloc                 p_bigstring

     c                   eval      *inlr = *on



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.