Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

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