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

  1. /**
  2. *
  3. * Name        stcright -- Extract the rightmost characters
  4. *
  5. * Synopsis    amov = stcright(ptarget,psource,cpos,tarsize);
  6. *
  7. *        int amov      Number of characters extracted
  8. *        char *ptarget      Pointer to target string
  9. *        char *psource      Pointer to source string
  10. *        int cpos      Starting position from which to
  11. *                  extract characters.
  12. *        int tarsize      The maximum length of ptarget.
  13. *
  14. * Description    STCRIGHT extracts the rightmost characters of psource
  15. *        starting at character position cpos (characters are
  16. *        numbered from 0).  The characters are moved to the
  17. *        string ptarget, but no more than tarsize minus 1
  18. *        characters are transferred.  The actual number of
  19. *        characters extracted is returned.
  20. *
  21. * Returns    amov          The number of characters moved.
  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 <string.h>
  29.  
  30. #include <bstring.h>
  31.  
  32. int stcright(ptarget,psource,cpos,tarsize)
  33. register char *ptarget,*psource;
  34. int          cpos,tarsize;
  35. {
  36.     register  int i,npos;
  37.  
  38.     npos = (int) strlen(psource);      /* Compute the starting position*/
  39.     npos = max(0,min(npos,cpos));      /* within psource.           */
  40.     psource += npos;
  41.     for (i = 0; (i < (tarsize - 1)) && (*ptarget++ = *psource++); i++);
  42.     *ptarget = '\0';
  43.  
  44.     return(i);
  45. }
  46.