I've been having some problems trying to extract the GET variables from URL. This is what the url looks like:

www dot example dot com/live/t00/250lo.gif?tr7zt8&uid=4ccc6cd4fc7cc630&CXNID=2000001.5215456080540439072NXC&pub=telegraphmedia&rev=86981&si=4d28ac59f9a3d32e&lc=MDAwMDBFVUdCRU4yMzE4MTgwNDAwMDAwMDBDVg%3D%3D&ln=en&pc=tbx&uf=0&pi=1&dp=www.telegraph.co.uk&fp=news%2Fuknews%2F8248083%2FFather-drowns-while-trying-to-rescue-dogs.html

it's a bit long, but basically each variable is separated by an ampersand, so we have, for example:
uid=4ccc6cd4fc7cc630&CXNID=2000001.5215456080540439072NXC&pub=telegraphmedia&rev=86981

which translates into:
uid=4ccc6cd4fc7cc630
CXNID=2000001.5215456080540439072NXC
pub=telegraphmedia
rev=86981

my algorithm is:

char * var_m=...
char * tmp_m=...
char * amp_m=...
int i_m=...,offset_m=...
int len_m=strlen(var_m);
for(i_m=0;i_m<len_m;i_m++) {
    if(var_m[i_m]=='&') {
        fwrite(var_m+offset_m, 1, amp_m, echo_out);
        fputc('\n',echo_out);
        //this was an alternative method i used but it gave me a buffer overflow
        //strncpy(tmp_m,(var_m+i_m),amp_m-2);
        //fprintf(echo_out,"%s\n",tmp_m);
        offset_m+=amp_m;
        amp_m=0;
    }
    amp_m++;

}

this prints out garbled data rather than the variables each on a seperate line.Why?

Edited 5 Years Ago by eminhanif: n/a

please replace ... with appropriate values, so that we can see the code.
Moreover usage of amp_m (char *) is wrong.
Vinayak

This article has been dead for over six months. Start a new discussion instead.