I have a string which is of the format Contact:
<[email protected]:5060;gr=xyz123>;+g134,<more_text> I need to extract the content between the opening < and closing > There can be multiple instances of < and > , but I have to take the content from the pair in which the parameter gr= is present (only one occurrence of this).
To solve this what I did was:
ptr = strstr(str,"gr="); if(ptr) { temp1= ptr; while(*temp1 && *temp1!='<') { temp1--; } strncpy(newstring,temp1,ptr-temp1); //will copy upto start of gr temp2 = strstr(ptr,">") if(temp2) strncat(newstring,ptr,temp2-ptr); // copy remaining string till it finds closing '>' } It works fine, but I would like to know if there is anyway to avoid the while loop and going backwards?
newstringall in one go (fromtemp1totemp2).