Skip to content

Instantly share code, notes, and snippets.

@sudar
Created August 20, 2012 14:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sudar/3404970 to your computer and use it in GitHub Desktop.
Save sudar/3404970 to your computer and use it in GitHub Desktop.
URLEncoding in C
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