I ahve a long string of which I want to remove certain words....
string example =" <this> is some <test> data"
I want to remove words with are contained with "<>"...so after my programs runs I would be left with
<"is some data">
does anybody have idea's what function I could use...to remove such text from the string...
any ideas would be great...
A for loop and a boolean variable used to control the copying of chars
You set the bool to false when you see a <
You set it to true when you see a >
If it's true, copy the char
Try this. Keep in mind, the code will modify the string directly.
void RemoveWords(char *str);
int main(int argc, char* argv)
strcpy(str, "<this> is some <test> data");
#define START_CHAR '<'
#define END_CHAR '>'
p = str;
t = p;
while (*t) // while we haven't found the end of the string
if (*t == START_CHAR)
while (*t && *t != END_CHAR) // look for the END_CHAR
t++; // skip the END_CHAR
*p = *t; // finally, copy the current character
if (*t == '\0')
*p = '\0';