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

  1. /**
  2. *
  3. * Name        stcleft -- Extract leftmost characters from a string
  4. *
  5. * Synopsis    amov = stcleft(ptarget,psource,cnt,tarsize)
  6. *
  7. *        int amov      Actual number of characters moved
  8. *        char *ptarget      Pointer to target string
  9. *        char *psource      Pointer to source string
  10. *        int cnt       Number of characters to extract
  11. *        int tarsize      Maximum size of ptarget
  12. *
  13. * Description    This function extracts the cnt leftmost characters from
  14. *        psource and returns the characters in ptarget.    The
  15. *        number of characters extracted is no greater than the
  16. *        length of the source string, or the maximum size of the
  17. *        target string minus 1 (to account for the trailing
  18. *        '\0').  The actual number of characters extracted is
  19. *        returned as the function value.
  20. *
  21. * Returns    amov          The number of characters extracted.
  22. *        ptarget       The string of extracted characters.
  23. *
  24. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  25. *
  26. **/
  27.  
  28. #include <bstring.h>
  29.  
  30. int stcleft(ptarget,psource,cnt,tarsize)
  31. register char  *ptarget,*psource;
  32. register int   cnt;
  33. int           tarsize;
  34. {
  35.     register   int i;
  36.  
  37.     utbound(cnt,0,tarsize - 1)          /* Number of characters to move.*/
  38.     for (i = 0; (i < cnt) && (*ptarget++ = *psource++); i++)
  39.     ;
  40.     *ptarget = '\0';
  41.  
  42.     return(i);
  43. }
  44.