# Thread: what is the purpose of this function..

1. ## what is the purpose of this function..

true=1
false=0

i dont need to a solution
i want a way by which i can decide
what this function do

here i have arrays of input
very complicated
where to start
how to go?

Code:
```int what2(char* s1,char* s2,char*s3,int* n1,int* n2)
{
int sz1=strlen(s1),sz2=strlen(s2);

if (!*s3)
{
*n1=*n2=0;
return true;
}
if (what1 (s1,s3) && what2(s1,s2,s3+sz1,n1,n2))
{
(*n1)++;
return true;
}
if (what1 (s2,s3)&& what2(s1,s2,s3+sz2,n1,n2))
{
(*n2)++;
return true;
}
return false;
}```

2. It changes the values at n1 and n2 depending on the values of the three strings.

If s3 holds 0, both n1 and n2 are also set to 0 and we're done. Otherwise, we check the return values of what1 and what2.

If what1(s1, s3) is true, we recursively call what2 with a slightly different s3 - with the first sz1 characters removed. If what2 also returns true, we increment n1 and finish.

If what1(s2, s3) is true, we recursively call what2 with a slightly different s3 - with the first sz2 characters removed. If what2 also returns true, we increment n2 and finish.

If none of those conditions was true, we're done.

3. what input ro use in order to find a pattern

4. Do we know what the what1() function does?

The whole thing looks kinda pointless. Both strings s1 and s2 never change, so why keep passing them through? And why recalculate their lengths every time? And why keep passing addresses n1 and n2 down the recursion? Lots of redundancy.

5. it seems to me like counting number of times s1 is present in s3 and s2 is present there (if the what1 returns true when first argument is equvalent to the beginning of the second string argument

s1 ="123"
s2="ab"
s3="123123123abab"
in a result n1 should be 3, n2 - 2

Popular pages Recent additions