I am trying to write a program in C, which will allow me to get a string I want between two other strings that will be defined. To be more specific, my example string is
"blahblah<mailto:[email protected]>blahblahblah"
and I need to be able to extract the "agent007" substring to a new variable. I have tried the strtok() method, but the thing is I can't extract the tokens to a new variable or an array. I have tokenized the string and the statement that would suite me fine would be something like " if token[i] == "mailto" && token[i+2] == "example" then mailAdd = token[i+1] " (in a pseudo-code way :) )
my program so far
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="blahblah<mailto:[email protected]>blahblahblah";
char * tch;
tch = strtok (str,"<:@");
while (tch != NULL)
{
printf ("%s\n",tch);
tch = strtok (NULL, "<:@");
}
return 0;
}
Of course, any other suggestion beyond tokens will be greatly appreciated -
tchstring somewhere:tchitself keeps changing. Note thatstrtokchanges the original string. After your loop, (if I didn't mess the calculations up)str+0points to "blahblah";str+9points to "mailto";str+16points to "agent007"; andstr+25points to "example.org>blahblahblah".