I'm trying to write a code that extracts all words/strings between the and tags using strstr. But it seems that it just gets stuck to the first string extracted, which is "quick". How can I get the code to keep going after extracting the first string?
#include <stdio.h>
#include <string.h>
int main()
{
char feed[] = "The <item> quick </item> brown <item> fox </item> jumps <item> over </item> the <item> lazy dog </item>";
const char needle[] = "<item>";
const char popo[] = "</item>";
char *ret;
char *ter;
int n;
n = 0;
while (feed[n] != '\0')
{
ret = strstr(feed, needle)+6;
ter = strstr(ret, popo);
size_t len = ter - ret;
char *res = (char*)malloc(sizeof(char)*(len+1));
strncpy(res, ret, len);
res[len] = '\0';
printf("%s",res);
n++;
}
return 0;
}