Skip to content

Instantly share code, notes, and snippets.

@dontangg
Created April 12, 2011 12:52
Show Gist options
  • Save dontangg/915445 to your computer and use it in GitHub Desktop.
Save dontangg/915445 to your computer and use it in GitHub Desktop.
Just a simple C program that reverses a string in place.
#include <stdio.h>
#include <string.h>
void reverse(char str[]) {
int len = strlen(str);
int i;
for(i = 0; i < (len / 2); i++) {
char c = str[i];
str[i] = str[len - i - 1];
str[len - i - 1] = c;
}
}
int main() {
char str[] = "Please reverse me";
printf("Original: [%s]\n", str);
reverse(str);
printf("Reversed: [%s]\n", str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment