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

  1. /***
  2. *wcsrchr.c - find last occurrence of wchar_t character in wide string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines wcsrchr() - find the last occurrence of a given character
  8. *       in a string (wide-characters).
  9. *
  10. *******************************************************************************/
  11.  
  12.  
  13. #include <cruntime.h>
  14. #include <string.h>
  15.  
  16. /***
  17. *wchar_t *wcsrchr(string, ch) - find last occurrence of ch in wide string
  18. *
  19. *Purpose:
  20. *       Finds the last occurrence of ch in string.  The terminating
  21. *       null character is used as part of the search (wide-characters).
  22. *
  23. *Entry:
  24. *       wchar_t *string - string to search in
  25. *       wchar_t ch - character to search for
  26. *
  27. *Exit:
  28. *       returns a pointer to the last occurrence of ch in the given
  29. *       string
  30. *       returns NULL if ch does not occurr in the string
  31. *
  32. *Exceptions:
  33. *
  34. *******************************************************************************/
  35.  
  36. wchar_t * __cdecl wcsrchr (
  37.         const wchar_t * string,
  38.         wchar_t ch
  39.         )
  40. {
  41.         wchar_t *start = (wchar_t *)string;
  42.  
  43.         while (*string++)                       /* find end of string */
  44.                 ;
  45.                                                 /* search towards front */
  46.         while (--string != start && *string != (wchar_t)ch)
  47.                 ;
  48.  
  49.         if (*string == (wchar_t)ch)             /* wchar_t found ? */
  50.                 return( (wchar_t *)string );
  51.  
  52.         return(NULL);
  53. }
  54.  
  55.