Skip to content

Instantly share code, notes, and snippets.

@Charles-Hsu
Created April 27, 2017 13:58
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 Charles-Hsu/f5b39740699283bc3a860a10acae2bc6 to your computer and use it in GitHub Desktop.
Save Charles-Hsu/f5b39740699283bc3a860a10acae2bc6 to your computer and use it in GitHub Desktop.
reverse a string
void reverse(char *str)
{
char *end = str;
char tmp;
if (str) {
while (*end) end++;
end--;
while (str < end) {
/* swap the character */
tmp = *end;
*str++ = *end;
*end-- = tmp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment