/*+JMJ
 * kahara.c - QUERY_STRING parsing in plain C
 * 
 * Source: Joni Kahara. QUERY_STRING parsing in plain C. Async.fi. 
 * 2011/1/10. <http://async.fi/2011/01/query_string-parsing-in-plain-c/>
 * accessed 2011/5/19.
 */

/* C source code fragment ... */

char * query = getenv("QUERY_STRING");
char * pair;
char * key:
double value;
if (query && strlen(query) > 0) {
  pair = strtok(query, "&");
  while (pair) {
    key = (char *)malloc(strlen(pair)+1);
    sscanf(pair, "%[^=]=%lf", key, &value;);
    if (!strcmp(key, "lat")) {
      lat = value;
    } else if (!strcmp(key, "lng")) {
      lng = value;
    }
    free(key);
    pair = strtok((char *)0, "&");
  }
}