summaryrefslogtreecommitdiff
path: root/urlencode.c
diff options
context:
space:
mode:
Diffstat (limited to 'urlencode.c')
-rw-r--r--urlencode.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/urlencode.c b/urlencode.c
new file mode 100644
index 0000000..5a418f2
--- /dev/null
+++ b/urlencode.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <string.h>
+
+int main() {
+ char str[2047];
+ char safe[] = "ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz1234567890-._~";
+ char *ret;
+ int i;
+
+ scanf("%[^\n]", str);
+
+ for(i = 0; i < (strlen(str)); i++) {
+
+ ret = strchr(safe, str[i]);
+ if(ret == NULL) {
+ printf("%%%02X", (unsigned)str[i] & 0xffU);
+ } else {
+ printf("%c", str[i]);
+ }
+ }
+
+ printf("\n");
+ return 0;
+}