Created
April 27, 2017 13:58
-
-
Save Charles-Hsu/f5b39740699283bc3a860a10acae2bc6 to your computer and use it in GitHub Desktop.
reverse a string
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
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