summaryrefslogtreecommitdiff
path: root/urlencode.c
diff options
context:
space:
mode:
Diffstat (limited to 'urlencode.c')
-rw-r--r--urlencode.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/urlencode.c b/urlencode.c
new file mode 100644
index 0000000..a8c61ad
--- /dev/null
+++ b/urlencode.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2015 Luke Shumaker <lukeshu@sbcglobal.net> */
+#include <stdio.h>
+
+int
+main () {
+ int c;
+ while ((c = getchar()) != EOF) {
+ if (('0' <= c && c <= '9')
+ || ('A' <= c && c <= 'Z')
+ || ('a' <= c && c <= 'z')
+ ){
+ putchar(c);
+ } else if (c == ' ') {
+ putchar('+');
+ } else {
+ printf("%%%02X", c);
+ }
+ }
+ return 0;
+}