Skip to content

Instantly share code, notes, and snippets.

@u2
Forked from sudar/url-encode.c
Created January 3, 2014 02:31
Show Gist options
  • Select an option

  • Save u2/8231574 to your computer and use it in GitHub Desktop.

Select an option

Save u2/8231574 to your computer and use it in GitHub Desktop.
int c;
char *hex = "0123456789abcdef";
while( (c = getchar()) != EOF ){
if( ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') ){
putchar(c);
} else {
putchar('%');
putchar(hex[c >> 4]);
putchar(hex[c & 15]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment