I have the following string :
GET /index.html HTTP/1.0;;User-Agent: Wget/1.11.4;;Accept: */*;;Host: www.google.com;;Connection
I use the following code to parse each element:
while (parser != NULL){
printf ("%s\n",parser);
parser = strtok (NULL, ";;");
}
This outputs:
GET /index.html HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: www.google.com
Connection
Now I only need to get host web address which in this case is www.google.com. So first I want to separate it from other stuff.
To do that I put another parser inside my previous one like so:
while (parser != NULL){
char * pars = strtok (string,":");
while (pars != NULL) {
printf("%s\n", pars);
pars = strtok (NULL, ":");
}
parser = strtok (NULL, ";;");
}
The output of this is some messed up stuff. I do not understand why... Can anyone see mistake? Thanks