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 / STRR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  2.1 KB  |  114 lines

  1. /*
  2.  * strr.c
  3.  * contains: strr(),strrlf(),strrt()
  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. /*
  14.  *  int
  15.  * strr(ps,repl,start,num)
  16.  *
  17.  * ARGUMENT
  18.  *  (char *)    ps    -    pointer to string to be operated on
  19.  *  (char)    repl    -    character to substitute in string
  20.  *  (int)    start    -    position at which to start (0==leftmost)
  21.  *  (int)    num    -    number of characters to replace
  22.  *
  23.  * DESCRIPTION
  24.  *  Replace characters in string starting at position indicated by
  25.  *  start.
  26.  *
  27.  * RETURNS
  28.  *  Actual number of characters replaced.
  29.  */
  30. int GF_CONV strr(ps,repl,start,num)
  31. char *ps,repl;
  32. int start,num;
  33. {
  34.     int i,j;
  35.     j=i=0;
  36.     while(*ps) {
  37.         if(i==start) 
  38.             break;
  39.         ++i;
  40.         ++ps;
  41.     }
  42.     if(i<start) 
  43.         return 0;    /* if start is past end of string    */
  44.     while (*ps) {
  45.         *ps = repl;
  46.         ++j;
  47.         if(j==num) 
  48.             break;
  49.         ++ps;
  50.     }
  51.     return j;
  52. }
  53.  
  54. /*
  55.  *  int
  56.  * strrlf(ps,repl,num)
  57.  *
  58.  * ARGUMENT
  59.  *  (char *)    ps    -    pointer to string to be operated on
  60.  *  (char)    repl    -    character to substitute in string
  61.  *  (int)    num    -    number of characters to replace
  62.  *
  63.  * DESCRIPTION
  64.  *  Replace characters in string starting at left most position.
  65.  *
  66.  * RETURNS
  67.  *  Actual number of characters replaced.
  68.  */
  69. int GF_CONV strrlf(ps,repl,num)
  70. char *ps,repl;
  71. int num;
  72. {
  73.     int iret,quan,min1;
  74.  
  75.     min1=xmin(num,strlen(ps));
  76.     quan=xmax(0,min1);
  77.     iret=quan;
  78.     while(quan--) 
  79.         *ps++=repl;
  80.     return iret;
  81. }
  82.  
  83. /*
  84.  *  int
  85.  * strrrt(ps,repl,num)
  86.  *
  87.  * ARGUMENT
  88.  *  (char *)    ps    -    pointer to string to be operated on
  89.  *  (char)    repl    -    character to substitute in string
  90.  *  (int)    num    -    number of characters to replace
  91.  *
  92.  * DESCRIPTION
  93.  *  Replace characters in string starting at right most position.
  94.  *
  95.  * RETURNS
  96.  *  Actual number of characters replaced.
  97.  */
  98. int GF_CONV strrrt(ps,repl,num)
  99. char *ps,repl;
  100. int num;
  101. {
  102.     int iret,quan,min1;
  103.  
  104.     min1=xmin(num,strlen(ps));
  105.     quan=xmax(0,min1);
  106.     iret = quan;
  107.     while(*ps++) 
  108.         ;
  109.     --ps;
  110.     while(quan--) 
  111.         *--ps=repl;
  112.     return iret;
  113. }
  114.