Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Created January 27, 2015 09:17
Show Gist options
  • Save iwagaki/235807342b355c2fbca7 to your computer and use it in GitHub Desktop.
Save iwagaki/235807342b355c2fbca7 to your computer and use it in GitHub Desktop.
reverse string
#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