Skip to content

Instantly share code, notes, and snippets.

@JoyceeLee
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoyceeLee/4e200d7a93e376415d67 to your computer and use it in GitHub Desktop.
Save JoyceeLee/4e200d7a93e376415d67 to your computer and use it in GitHub Desktop.
/*
*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