Skip to content

Instantly share code, notes, and snippets.

Created June 16, 2014 14:44
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 anonymous/437c05fb726da019ff52 to your computer and use it in GitHub Desktop.
Save anonymous/437c05fb726da019ff52 to your computer and use it in GitHub Desktop.
#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