home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / DATABASE / CLIPPC.ZIP / ALPHN.C next >
Encoding:
C/C++ Source or Header  |  1988-03-02  |  2.0 KB  |  81 lines

  1. /*
  2.    File: AlphN.prg
  3.  
  4.    Author: Mark Pfeifer
  5.  
  6.    Compiler:  Turbo-C (tm), v 1.5
  7.               Clipper (tm), Summer '87
  8.  
  9.    Revision:
  10.       2-Mar-88    initial coding
  11.  
  12.    Copyright: none, placed in the public domain by author
  13.  
  14. */
  15.  
  16.    /* Clipper-C interface header info */
  17.    /*    Note: This is a modified version of EXTEND.H and NANDEF.H */
  18.    #include <CLIP_C.H>
  19.  
  20. /* func AlphaN
  21.  
  22.    syntax:   AlphaN(<exp-N>)
  23.       where <exp-N> is number from 0 to 35 to be converted to an Alpha
  24.    returns:  string of 1 char
  25.  
  26.    This function comes in handy when accessing multiple parameters,
  27.    for example, see the UpEq function.
  28.  
  29.    AlphaN converts a number from 0 to 35 to an Alpha as follows:
  30.  
  31.               <exp-N>  return value
  32.                  0        '0'
  33.                  1        '1'
  34.                      ...
  35.                  9        '9'
  36.                 10        'A'
  37.                 11        'B'
  38.                      ...
  39.                 34        'Y'
  40.                 35        'Z'
  41.  
  42. */
  43.  
  44. CLIPPER AlphaN()
  45.    {
  46.    /* local variables */
  47.  
  48.    CL_ni pN ;      /* C var to receive parameter */
  49.    CL_c mRet ;     /* C var to be used to pass result back */
  50.  
  51.    if ( PCOUNT==1 )   /* Check to make sure a parameter was passed */
  52.       {
  53.       /* get parameters */
  54.          if ( !ISNUM( (CL_par)1 ) ) goto err_out ;
  55.  
  56.          pN=_parni( (CL_par)1 ) ;
  57.          if ( pN>35  || pN<0 ) goto err_out ;
  58.  
  59.       /* main code */
  60.          mRet= (CL_c)_exmgrab( (CL_msiz)2 ) ;  /* grab 2 bytes to use */
  61.          if (!mRet ) goto err_out ;        /* check to be sure we got it */
  62.  
  63.          mRet[0]= pN<10 ? pN+48 : pN+55 ;  /* do conversion */
  64.          mRet[1]= 0 ; /* append null terminator */
  65.  
  66.          _retc(mRet) ;  /* return string to clipper */
  67.  
  68.          _exmback( (CL_mptr)mRet, (CL_msiz)2 ) ; /* give the 2 bytes back */
  69.  
  70.       }
  71.  
  72.    else
  73.       {
  74.       /* invalid parms code */
  75.       err_out:
  76.          _retc( (CL_c)"" ) ;
  77.  
  78.       }
  79.    /* end of function */
  80.    }
  81.