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

  1. /**
  2. *
  3. * Name        stpword -- Extract next word from a string
  4. *
  5. * Synopsis    presult = stpword(ptarget,psource,tarsize);
  6. *
  7. *        char *presult      Pointer to next character in source
  8. *        char *ptarget      Pointer to target string
  9. *        char *psource      Pointer to source string
  10. *        int  tarsize      Size of target string (including space
  11. *                  for trailing NUL ('\0'))
  12. *
  13. * Description    This function skips any leading white space in the
  14. *        source string and copies the succeeding characters from
  15. *        the source to the target until more white space or the
  16. *        end of the source is encountered or until the target
  17. *        string is full.  A pointer to the next character in the
  18. *        source string is returned.  If no nonwhite characters
  19. *        are found then the target string will be the null string
  20. *        (zero length).
  21. *
  22. *        White space (blanks, tabs, newlines, etc.) is defined by
  23. *        the isspace() function or macro.
  24. *
  25. * Returns    presult       Pointer to next character in source
  26. *        *ptarget      Next string of nonblanks from source
  27. *
  28. * Version    3.0 (C)Copyright Blaise Computing Inc.    1986
  29. *
  30. **/
  31.  
  32. #include <ctype.h>
  33. #include <bstring.h>
  34.  
  35. #define BLANK    ' '
  36.  
  37. char *stpword(ptarget,psource,tarsize)
  38. register char *ptarget;
  39. char          *psource;
  40. int          tarsize;
  41. {
  42.     while (isspace(*psource))          /* Step past leading white      */
  43.     psource++;              /* space in source.          */
  44.  
  45.     while (   --tarsize > 0          /* While target not full          */
  46.        && *psource              /* and source not exhausted     */
  47.        && !(isspace(*psource)))
  48.     *ptarget++ = *psource++;      /* copy nonblanks.          */
  49.  
  50.     *ptarget = '\0';
  51.  
  52.     return psource;
  53. }
  54.