home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / wcsstr.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  61 lines

  1. /***
  2. *wcsstr.c - search for one wide-character string inside another
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines wcsstr() - search for one wchar_t string inside another
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *wchar_t *wcsstr(string1, string2) - search for string2 in string1
  17. *       (wide strings)
  18. *
  19. *Purpose:
  20. *       finds the first occurrence of string2 in string1 (wide strings)
  21. *
  22. *Entry:
  23. *       wchar_t *string1 - string to search in
  24. *       wchar_t *string2 - string to search for
  25. *
  26. *Exit:
  27. *       returns a pointer to the first occurrence of string2 in
  28. *       string1, or NULL if string2 does not occur in string1
  29. *
  30. *Uses:
  31. *
  32. *Exceptions:
  33. *
  34. *******************************************************************************/
  35.  
  36. wchar_t * __cdecl wcsstr (
  37.         const wchar_t * wcs1,
  38.         const wchar_t * wcs2
  39.         )
  40. {
  41.         wchar_t *cp = (wchar_t *) wcs1;
  42.         wchar_t *s1, *s2;
  43.  
  44.         while (*cp)
  45.         {
  46.                 s1 = cp;
  47.                 s2 = (wchar_t *) wcs2;
  48.  
  49.                 while ( *s1 && *s2 && !(*s1-*s2) )
  50.                         s1++, s2++;
  51.  
  52.                 if (!*s2)
  53.                         return(cp);
  54.  
  55.                 cp++;
  56.         }
  57.  
  58.         return(NULL);
  59. }
  60.  
  61.