Reactos
at master 51 lines 1.1 kB view raw
1/*** 2*strrev.c - reverse a string in place 3* 4* Copyright (c) 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 <string.h> 13 14/*** 15*char *_strrev(string) - reverse a string in place 16* 17*Purpose: 18* Reverses the order of characters in the string. The terminating 19* null character remains in place. 20* 21*Entry: 22* char *string - string to reverse 23* 24*Exit: 25* returns string - now with reversed characters 26* 27*Exceptions: 28* 29*******************************************************************************/ 30 31char * __cdecl _strrev ( 32 char * string 33 ) 34{ 35 char *start = string; 36 char *left = string; 37 char ch; 38 39 while (*string++) /* find end of string */ 40 ; 41 string -= 2; 42 43 while (left < string) 44 { 45 ch = *left; 46 *left++ = *string; 47 *string-- = ch; 48 } 49 50 return(start); 51}