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

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