>Date: Wed, 23 Jan 2002 12:51:59 -0800
>From: "Eric Kempter" <EKempter@norcalwaste.com>
>Would someone please give me an example of how to use the isalpha C
>runtime function within an ILE pgm.  I have printed examples on how to
>use C functions from the archives and referenced the Sorcerer's guide
>but I am missing something.  The following is my (failing) code.  I am
>attempting to determine if any alpha characters exist within a string.
>H dftactgrp(*no) bnddir('QC2LE')
>D num             s             10I 0
>D str                s            10    inz('ABC')
>D isalpha         pr                  ExtProc('isalpha')
>D                                   10I 0 Value
>C                   eval      num = isalpha(str)
>C     num        dsply
>C                   eval      *inlr = *on

Eric, you can only call isalpha for one byte at a time.  Since
it takes an integer parameter, you'll have to convert your
characters to integer, too.

If you have V5R1 (notice the change to the EXTPROC keyword
for the isalpha prototype):

D                    ds
D str                             10    inz('ABC')
D strInts                          3i 0 overlay(str)
D                                       dim(%size(str))

D isalpha         pr                    ExtProc(*CWIDEN:
D                                               'isalpha')
D                                10I 0 Value

C        eval    hasAlpha = '0'
C        for     i = 1 to %len(str)
C        if      isalpha (strInts(i)) <> '1'
C        eval    hasAlpha = '1'
C        endif
C        endfor

If you don't have V5R1 (sorry about the spacing), you
have to handle the integer widening yourself.
(See http://www.opensource400.org/callc.html for a bit
about C widening and how it affects RPG.)

  D charToInt    PR           10I 0
  D   A                        1A   VALUE

  C        eval    hasAlpha = '0'
  C        for     i = 1 to %len(str)
  C        if      isalpha (charToInt(str(i))) <> '1'
  C        eval    hasAlpha = '1'
  C        endif
  C        endfor

  P charToInt    B                  EXPORT
  D charToInt    PI           10I 0
  D   A                        1A   VALUE

  D              DS
  D  int                      10I 0 INZ(0)
  D  chr                       1A   OVERLAY(int:4)
  C        eval       chr = A
  C        return     int
  P charToInt    E

Barbara Morris

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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

This mailing list archive is Copyright 1997-2022 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.