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




> I tried using the below C Function incapsulated in an ile Service Pgm. When
> I debug the call to the function strsep, the paramter delimiter has the
> delimiter(s)  I passed but the stringp Parm always starts off as NULLand the
> function promptly ends as the code says to. I don't Understand what the
> prototype in Rpg must be for this function to work properly. I thought the
> interface was identical to Strtok(). What does **stringp mean??

First, I don't know why you think the interface is identical to strtok()?
It serves the same purpose, but doesn't have the same parameters...

Second, I don't understand why you don't just write an RPG subprocedure
to loop through the string and find the delimiter character(s)?  wouldn't
that be easier than trying to call strsep()?   It seems like it's almost
more code to use strsep than it would be to write strsep in the first
place!

Okay, I'll stop grumbling and answer your questions.

"char **stringp"  means that the procedure wants the address of a pointer.
That pointer, in turn, points to a null-terminated character string.

Another way of looking at it...   "char *string" is a pointer to a
character string.   "char **stringp" is a pointer to a pointer to a
character string.

Why does it do that?   Because it needs to change the position of the
pointer with each successive call, in order to change the value of the
POINTER, you must pass the POINTER by reference.  (otherwise changes in
the subprocedure would nto be reflected back in the mainline)

Since, from RPG's perspective, what you're passing is the address of a
pointer, you cannot use options(*string), either.   You'll have to
manually convert the string, either by concatenating x'00' to the end,
or by calling the %str() BIF.

Here's a sample of calling strsep() from RPG:

     D strsep          PR              *   extproc('strsep')
     D   stringp                       *   value
     D   delim                         *   value options(*string)

     D input           s            200A
     D p_input         s               *
     D p_retval        s               *
     D word            s             50A   varying

      /free
         p_input = %addr(input);
         %str(p_input: %size(input)) = 'This string will be separated ' +
            'into words even-if-the-words-are-separated-by-dashes';

         p_retval = strsep(%addr(p_input): ' -');
         dow (p_retval <> *NULL);
             word = %str(p_retval);
             dsply '' '' word;
             p_retval = strsep(%addr(p_input): ' -');
         enddo;

         *inlr = *on;
      /end-free

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.