Skip to content

Instantly share code, notes, and snippets.

@aruslan
Created April 20, 2012 00:34
Show Gist options
  • Save aruslan/2425032 to your computer and use it in GitHub Desktop.
Save aruslan/2425032 to your computer and use it in GitHub Desktop.
revndup
#include <stdio.h>
void shodan_ndup(char* s) {
char* p = s;
for(; *s; ++s)
if (*s != s[1])
*p++ = *s;
*p = 0;
}
void shodan_rev(char* s) {
char* p = s;
for(; *p ; ++p) {}
if (p>s)
for(--p; p>s; --p, ++s) {
const char t = *p; *p = *s; *s = t;
}
}
int main() {
{ char s[] = ""; shodan_rev(s); printf("%s\n", s); }
{ char s[] = "H"; shodan_rev(s); printf("%s\n", s); }
{ char s[] = "He"; shodan_rev(s); printf("%s\n", s); }
{ char s[] = "Hel"; shodan_rev(s); printf("%s\n", s); }
{ char s[] = ""; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "H"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "HH"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "HHh"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "HHhh"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "HHell"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "Hell"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "Hel"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "Hello world"; shodan_rev(s); printf("%s\n", s); }
{ char s[] = "HHellooo worldd"; shodan_ndup(s); printf("%s\n", s); }
{ char s[] = "HHellooo worldd"; shodan_rev(s); shodan_ndup(s); shodan_rev(s); printf("%s\n", s); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment