home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / STCFILL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.5 KB  |  57 lines

  1. /**
  2. *
  3. * Name        stcfill -- Fill n characters at a position
  4. *
  5. * Synopsis    amov = stcfill(ptarget,ch,cpos,cnt,tarsize);
  6. *
  7. *        int amov      Actual number of characters placed
  8. *                  in ptarget.
  9. *        char *ptarget      Pointer to returned altered string
  10. *        char ch       Character to fill in ptarget
  11. *        int cpos      Position in ptarget to place copies
  12. *                  of ch.
  13. *        int cnt       Number of copies of ch to fill
  14. *        int tarsize      Maximum length of ptarget.
  15. *
  16. * Description    This procedure places cnt copies of the character ch in
  17. *        the string ptarget beginning at position cpos.    The
  18. *        extreme cases are handled in the same way as STCMID.
  19. *
  20. * Returns    amov          The number of copies of ch moved
  21. *        ptarget       The altered string
  22. *
  23. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  24. *
  25. **/
  26.  
  27. #include <string.h>
  28.  
  29. #include <bstring.h>
  30.  
  31. #define BLANK     ' '
  32.  
  33. int stcfill(ptarget,ch,cpos,cnt,tarsize)
  34. register char *ptarget;
  35. char ch;
  36. int  cnt,cpos,tarsize;
  37. {
  38.     int npos,n,len;
  39.     register    int i;
  40.  
  41.     /* First set up reasonable values for the number of copies of ch   */
  42.     /* and the position within ptarget.                    */
  43.  
  44.     len  = (int) strlen(ptarget);
  45.     npos = min(max(0,cpos),len);
  46.     n     = min(cnt,tarsize - npos);
  47.  
  48.     ptarget += npos;
  49.     for (i = 0; i < n; i++)           /* Copy the string           */
  50.     *ptarget++ = ch;
  51.  
  52.     if ((npos + n) >= len)
  53.        *ptarget = '\0';                /* String extension             */
  54.  
  55.     return(i);
  56. }
  57.