Skip to content

Instantly share code, notes, and snippets.

@gar
Created April 1, 2011 18:52
Show Gist options
  • Save gar/898647 to your computer and use it in GitHub Desktop.
Save gar/898647 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define MAXLEN 256
void reverse(char *s, char *r);
main() {
char s[MAXLEN] = "hello reversed world!";
char r[MAXLEN];
reverse(s, r);
printf("%s\n", r);
}
void reverse(char *s, char *r) {
int i = strlen(s)-1;
int j = 0;
while((r[j++] = s[i--]) != '\0');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment