Last active
August 29, 2015 14:02
-
-
Save JoyceeLee/4e200d7a93e376415d67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*1.2 Implement a function void reverse(char* str) in C or C++ which reverses a null-terminated string. | |
**/ | |
void reverse(char* str) { | |
char* end = str; | |
if(str) { | |
while(*end) { | |
end++; | |
} | |
end--; | |
char tmp; | |
while(str<end) { | |
tmp = *str; | |
*str++ = *end; | |
*end-- = tmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment