Created
December 17, 2015 16:18
-
-
Save masterzorag/4203f911cb43ce0ebb99 to your computer and use it in GitHub Desktop.
C URL encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://gist.githubusercontent.com/sudar/3404970/raw/3f085b750aaa2ff2f49b148827a19915a4857222/url-encode.c | |
gcc -o test urlenc.c -Wall | |
./test "[a b]" | |
%5ba%20b%5d | |
*/ | |
#include <stdio.h> | |
int main (int argc, char *argv[]) | |
{ | |
char *hex = "0123456789abcdef", *c = argv[1]; | |
while(*c != '\0') | |
{ | |
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]); | |
} | |
c++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment