summaryrefslogtreecommitdiff
path: root/urlencode.c
blob: a8c61ad351b6d94a69a6483137d04eec218fd937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}