Skip to content

Instantly share code, notes, and snippets.

@Veejay
Created April 13, 2012 14:58
Show Gist options
  • Save Veejay/2377452 to your computer and use it in GitHub Desktop.
Save Veejay/2377452 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
char* reverse(char *s)
{
int i, placeholder;
int l = strlen(s) - 1;
for(i = 0; i < (l / 2); i++){
placeholder = *(s+i);
*(s+i) = *(s+l-i);
*(s+l-i) = placeholder;
}
return s;
}
int main()
{
char s[] = "this is a test string";
printf("The reversed version of \"%s\" is ", s);
printf("\"%s\"\n", reverse(s));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment