home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / STRSPN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.9 KB  |  53 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strspn.c
  3.  *
  4.  * function(s)
  5.  *        strspn - scans a string for the first segment that is a
  6.  *                 subset of a given set of characters
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #include <string.h>
  20.  
  21. /*---------------------------------------------------------------------*
  22.  
  23. Name            strspn - scans a string for the first segment that is a
  24.                          subset of a given set of characters
  25.  
  26. Usage           size_t strspn(const char *str1, const char *str2);
  27.  
  28. Prototype in    string.h
  29.  
  30. Description    strspn returns the length of the initial segment of string
  31.         str1 that consists entirely of characters from string str2.
  32.  
  33. Return value    strspn returns the length of the initial segment of string
  34.         str1 that consists entirely of characters from string str2.
  35.  
  36.  
  37. *---------------------------------------------------------------------*/
  38. size_t strspn(const char *s1, const char *s2)
  39. {
  40.     register const char *srchs2;
  41.     int            len;
  42.  
  43.     for (len = 0; *s1; s1++, len++)
  44.     {
  45.         for (srchs2 = s2; *srchs2; srchs2++)
  46.             if (*s1 == *srchs2)
  47.                 break;
  48.         if (*srchs2 == 0)
  49.             break;
  50.     }
  51.     return (len);
  52. }
  53.