I want to print the data between tags from a text file using C.
Input statement :
<PERSON> Mark Zuckerberg </PERSON> is a entrepreneur from <LOCATION> USA </LOCATION>. He is also the CEO of <ORGANIZATION> Facebook </ORGANIZATION>.
Output: Mark Zuckerberg USA Facebook.
My Program code is :
const char* getfield(char* line, int num)
{
const char* tok;
for (tok = strtok(line, "/>");
tok && *tok;
tok = strtok(NULL, ">"))
{
if (!--num)
return tok;
}
return NULL;
}
int main()
{
char line[500000];
while (fgets(line, 500000, stdin))
{
char *arg = line;
const char *tok;
while ((tok = getfield(arg, 2)) != NULL) {
printf("%s\n", tok);
arg = NULL;
}
}
}
My output is :
Mark Zuckerberg </PERSON
USA </LOCATION
Facebook </ORGANIZATION
I want to get rid of </Tag
and get only Mark Zuckerberg USA Facebook as output. Where do I need to change the code?