Skip to content

Instantly share code, notes, and snippets.

@leroux
Created August 16, 2012 20:57
Show Gist options
  • Save leroux/112ba0a0134852bb7f20 to your computer and use it in GitHub Desktop.
Save leroux/112ba0a0134852bb7f20 to your computer and use it in GitHub Desktop.
Kiyoura's Reverse String Challenge Solution
#include <stdio.h>
int main (void) {
char str[] = "password";
int i = 0;
/* for pointer arithmetic */
char *ptr = str;
while (*ptr && (*ptr += (i++)))
ptr++;
printf("%s\n", str);
i = 0;
ptr = str; // repoint to beginning of string
while(*ptr && (*ptr -= (i++)))
ptr++;
printf("%s\n", str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment