home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name stcfill -- Fill n characters at a position
- *
- * Synopsis amov = stcfill(ptarget,ch,cpos,cnt,tarsize);
- *
- * int amov Actual number of characters placed
- * in ptarget.
- * char *ptarget Pointer to returned altered string
- * char ch Character to fill in ptarget
- * int cpos Position in ptarget to place copies
- * of ch.
- * int cnt Number of copies of ch to fill
- * int tarsize Maximum length of ptarget.
- *
- * Description This procedure places cnt copies of the character ch in
- * the string ptarget beginning at position cpos. The
- * extreme cases are handled in the same way as STCMID.
- *
- * Returns amov The number of copies of ch moved
- * ptarget The altered string
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <string.h>
-
- #include <bstring.h>
-
- #define BLANK ' '
-
- int stcfill(ptarget,ch,cpos,cnt,tarsize)
- register char *ptarget;
- char ch;
- int cnt,cpos,tarsize;
- {
- int npos,n,len;
- register int i;
-
- /* First set up reasonable values for the number of copies of ch */
- /* and the position within ptarget. */
-
- len = (int) strlen(ptarget);
- npos = min(max(0,cpos),len);
- n = min(cnt,tarsize - npos);
-
- ptarget += npos;
- for (i = 0; i < n; i++) /* Copy the string */
- *ptarget++ = ch;
-
- if ((npos + n) >= len)
- *ptarget = '\0'; /* String extension */
-
- return(i);
- }