A typical example: the old days
#define ishex(x) (((x) >= '0' && (x) <= '9') || ((x) >= 'a' && (x) <= 'f') || \
((x) >= 'A' && (x) <= 'F'))
if(isupper(c)) c = tolower(c);
value=(c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
if(isupper(c)) c = tolower(c);
value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
void main(int argc, char *argv[]) {
char *params, *data, *dest, *s, *tmp;
puts("Content-type: text/html\r\n");
puts("<html><header><title>Form Example</title></header>");
puts("<body><h1>My Example Form</h1>");
puts("<form action=\"form.cgi\" method=\"POST\">");
puts("Name: <input type=\"text\" name=\"name\">");
puts("Age: <input type=\"text\" name=\"age\">");
data = getenv("QUERY_STRING");
params = data; dest = data;
if(*data=='+') *dest=' ';
else if(*data == '%' && ishex(*(data+1)) && ishex(*(data+2))) {
*dest = (char) htoi(data + 1);
if(!strcmp(s,"name")) name = tmp+1;
else if(!strcmp(s,"age")) age = tmp+1;
} while(s=strtok(NULL,"&"));
printf("Hi %s, you are %s years old\n",name,age);