Created
January 27, 2015 09:17
-
-
Save iwagaki/235807342b355c2fbca7 to your computer and use it in GitHub Desktop.
reverse 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
#include <cstdio> | |
#include <cstdlib> | |
#include <string.h> | |
void reverse(char *str) | |
{ | |
char* ptr_start = str; | |
char* ptr_end = str + strlen(str) - 1; | |
while (ptr_start < ptr_end) | |
{ | |
char tmp = *ptr_start; | |
*ptr_start = *ptr_end; | |
*ptr_end = tmp; | |
ptr_start++; | |
ptr_end--; | |
} | |
} | |
int main() { | |
char str[] = "ABCDEFGH"; | |
printf("str = %s\n", str); | |
reverse(str); | |
printf("str = %s\n", str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment