home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / charmix.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  2KB  |  88 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: charmix.c
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: 24/05/93
  10.  * Revision..: 1.00
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*
  23.  *  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_CHARMIX()
  26.  *  $CATEGORY$
  27.  *      String
  28.  *  $ONELINER$
  29.  *      Amalgamate two strings to form the return value
  30.  *  $SYNTAX$
  31.  *      GT_CharMix(<cStr1>, <cStr2>) --> cRet
  32.  *  $ARGUMENTS$
  33.  *      <cStr1>  - A character string to mix
  34.  *      <cStr2>  - A character string to mix with
  35.  *  $RETURNS$
  36.  *      cRet     - A string consisting of all the characters in <cStr1>
  37.  *                 mixed with all the characters in <cStr2>
  38.  *  $DESCRIPTION$
  39.  *      Return a string consisting of all the characters in <cStr1>
  40.  *      mixed with the characters from <cStr2>.
  41.  *
  42.  *      NOTE:
  43.  *         invalid parameters will return ""
  44.  *  $EXAMPLES$
  45.  *
  46.  *      ? gt_CharMix("abc", "123")               // prints "a1b2c3"
  47.  *      ? gt_CharMix("abcde", "123")             // prints "a1b2c3de"
  48.  *      ? gt_CharMix("abc", "12345")             // prints "a1b2c345"
  49.  *
  50.  *  $END$
  51.  */
  52.  
  53. #include "extend.h"
  54.  
  55. CLIPPER
  56. charMix()
  57. {
  58.   char *s1, *s2, *s3;
  59.   int l1, l2, i, pos;
  60.  
  61.   if (ISCHAR(1) && ISCHAR(2)) {
  62.     s1  = _parc(1);
  63.     s2  = _parc(2);
  64.     l1  = _parclen(1);
  65.     l2  = _parclen(2);
  66.     pos = 0;
  67.  
  68.     s3  = _xgrab(l1 + l2);              // grab us some mem to work with
  69.  
  70.     for (i = 0; i < l1; i++) {
  71.       s3[pos++] = s1[i];
  72.  
  73.       if (i < l2)
  74.         s3[pos++] = s2[i];
  75.     }
  76.  
  77.     if (l2 > l1)
  78.       for (; i < l2; i++)
  79.         s3[pos++] = s2[i];
  80.  
  81.     s3[pos] = '\0';
  82.     _retc(s3);
  83.     _xfree(s3);                     // free alloc'ed mem
  84.   } else {
  85.     _retc((char *) NULL);           // parameter mismatch - error NullStr
  86.   }
  87. }
  88.