I'm using this recursive function to find the tags in a HTML, the output is okay as of now but I'm more interested in the return value of this function find_tag
which comes out to be :
-somelargenumber
html
head
body
where the -somelargenumber
is the returned value of function which is different every time I run the compiled program.
But according to I made the function it must return 0 at some point in time and not any other value. Can anybody explain this?
#include<string>
#include<regex>
#include<iostream>
#include<iomanip>
using namespace std;
int find_tag(const string& s,vector<string> & cont )
{
smatch m;
if(s.size()>0)
{
if(regex_search(s,m,regex("<(.*)>(.*)</\\1>")))
{
cont.push_back(m[1]);
find_tag(m[2],cont);
find_tag(m.suffix(),cont);
}
else
{
return 0;
}
}
else
{
return 0;
}
}
int main()
{
cmatch m;
vector<string> cont;
string data{"<html><head>head data</head><body>body data</body></html>"};
cout<<find_tag(data,cont);
if(!(cont.empty()))
{
for(auto &a:cont)
{
cout<<a<<endl;
}
}
else
cout<<"\n not found";
return 0;
}
PS: i m no trying to parse any HTML here i m just interested in the returned value of the function.
Aucun commentaire:
Enregistrer un commentaire