Created
June 16, 2014 14:44
-
-
Save anonymous/437c05fb726da019ff52 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
#include <iostream> | |
using namespace std; | |
void swap(char *a, char *b) | |
{ | |
char *t = a; | |
a = b; | |
b = t; | |
} | |
void reverse(char* str) | |
{ | |
// get the length of the string | |
int len; | |
for(len = 0; str[len] != '\0'; len++); | |
// swap front and end | |
for(int i = 0, j = len - 1; i < j; i++, j--) | |
swap(str[i], str[j]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment