Question: int getMatchCount(string s1, string s2) { if(s2.length() == 0 || s1.length() == 0) return -1; else if(s2.length() > s1.length()) return -2; int i=0, j=0, k
int getMatchCount(string s1, string s2)
{
if(s2.length() == 0 || s1.length() == 0)
return -1;
else if(s2.length() > s1.length())
return -2;
int i=0, j=0, k = 0;
int len1, len2;
len1 = s1.length();
len2 = s2.length();
for(i=0;i
{
j=0;
for(j=0;j if(s1[i+j]!=s2[j])
break;
if(j == len2)
{
k++;
j = 0;
}
}
return k;
}

could someone fix this error and rewrite the code for me?
C++
Test Expected Got Successful For substring: he and full string hellohe110- string sub- "he"; string full-"hellohello"; int count = getMatchCount (sub, full); checkResult(sub, full, count); Expected Answer: 2 Got Answer: -2 string sub""; string full -"hellohello"; int countgetMatchCount (sub, full); checkResult(sub, full, count); Successful Successful Successful For substring: abc def and full string abe string sub "abcdef"; string full "ab"; int count getMatchCount (sub, full); checkResult(sub, full, count); Expected Answer: -2 Got Answer: 1 string sub "Satur"; string full -"SaturdaySat"; int countgetMatchCount (sub, full); checkResult(sub, full, count); Successful For substring: Satur and full string Saturdaysate Expected Answer: 1 Got Answer: -2 string sub -"he Successful Successful string full ""; int count = getMatchCount (sub, full); checkResult(sub, full, count); Your code must pass all tests to earn any marks. Try again. Hide differences