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

  1. /***
  2. *wcsrev.c - reverse a wide-character string in place
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _wcsrev() - reverse a wchar_t string in place (not including
  8. *       L'\0' character)
  9. *
  10. *******************************************************************************/
  11.  
  12.  
  13. #include <cruntime.h>
  14. #include <string.h>
  15.  
  16. /***
  17. *wchar_t *_wcsrev(string) - reverse a wide-character string in place
  18. *
  19. *Purpose:
  20. *       Reverses the order of characters in the string.  The terminating
  21. *       null character remains in place (wide-characters).
  22. *
  23. *Entry:
  24. *       wchar_t *string - string to reverse
  25. *
  26. *Exit:
  27. *       returns string - now with reversed characters
  28. *
  29. *Exceptions:
  30. *
  31. *******************************************************************************/
  32.  
  33. wchar_t * __cdecl _wcsrev (
  34.         wchar_t * string
  35.         )
  36. {
  37.         wchar_t *start = string;
  38.         wchar_t *left = string;
  39.         wchar_t ch;
  40.  
  41.         while (*string++)                 /* find end of string */
  42.                 ;
  43.         string -= 2;
  44.  
  45.         while (left < string)
  46.         {
  47.                 ch = *left;
  48.                 *left++ = *string;
  49.                 *string-- = ch;
  50.         }
  51.  
  52.         return(start);
  53. }
  54.  
  55.