home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / STRI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  2.2 KB  |  124 lines

  1. /*
  2.  * stri.c
  3.  * contains: stri(),strilf(),strirt()
  4.  *
  5.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "gfuncts.h"
  11.  
  12. /*
  13.  *  int
  14.  * stri(ps,cins,start,num)
  15.  *
  16.  * ARGUMENT
  17.  *  (char *)    ps    -     pointer to string
  18.  *  (char)    cins    -    character to insert
  19.  *  (int)    start    -    position to begin insertion
  20.  *  (int)    num    -    number of times to insert character
  21.  *
  22.  * DESCRIPTION
  23.  *  The indicated character is inserted into the source string num times.
  24.  *  Beginning at the position indicated by start.
  25.  *
  26.  * SIDE EFFECTS
  27.  *  string is modified
  28.  *
  29.  * RETURNS
  30.  *  number of characters inserted
  31.  */
  32. int GF_CONV stri(ps,cins,start,num)
  33. char *ps,cins;
  34. int start,num;
  35. {
  36.     int i,k,len,GF_CONV strmove();
  37.     char *pt;
  38.  
  39.     len=strlen(ps);
  40.     if(!num||start>len) 
  41.         return 0;
  42.     i=k=0;
  43.     while(1) {
  44.         if(!*ps) 
  45.             return k;
  46.         if(i<start) {
  47.             ++i;
  48.             ++ps;
  49.         } else {
  50.             pt=ps;
  51.             ps+=num;
  52.             if(start<len) 
  53.                 strmove(ps,pt);
  54.             while(k<num) {
  55.                 pt[k]=cins;
  56.                 ++k;
  57.             }
  58.             if(start==len) 
  59.                 pt[k+1]='\0';
  60.             return k;
  61.         }
  62.     }
  63. }
  64.  
  65. /*
  66.  *  int
  67.  * strilf(ps,cins,num)
  68.  *
  69.  * ARGUMENT
  70.  *  (char *)    ps    -     pointer to string
  71.  *  (char)    cins    -    character to insert
  72.  *  (int)    num    -    number of times to insert character
  73.  *
  74.  * DESCRIPTION
  75.  *  The indicated character is inserted into the source string num times.
  76.  *  Beginning at the left.
  77.  *
  78.  * SIDE EFFECTS
  79.  *  string is modified
  80.  *
  81.  * RETURNS
  82.  *  number of characters inserted
  83.  */
  84. int GF_CONV strilf(str,c,num)
  85. char *str,c;
  86. int num;
  87. {
  88.     return(stri(str,c,0,num));
  89. }
  90.  
  91. /*
  92.  *  int
  93.  * strirt(ps,cins,num)
  94.  *
  95.  * ARGUMENT
  96.  *  (char *)    ps    -     pointer to string
  97.  *  (char)    cins    -    character to insert
  98.  *  (int)    num    -    number of times to insert character
  99.  *
  100.  * DESCRIPTION
  101.  *  The indicated character is inserted into the source string num times.
  102.  *  Beginning at the right.
  103.  *
  104.  * SIDE EFFECTS
  105.  *  string is modified
  106.  *
  107.  * RETURNS
  108.  *  number of characters inserted
  109.  */
  110. int GF_CONV strirt(str,c,num)
  111. char *str,c;
  112. int num;
  113. {
  114.     int i;
  115.  
  116.     while (*str++) 
  117.         ;
  118.     --str;
  119.     for (i=1;i<=num;i++)
  120.         *str++=c;
  121.     *str='\0';
  122.     return i;
  123. }
  124.