0

i want solution program for this program......

Given a string and a non-empty substring sub, compute the largest substring which starts and ends with sub and return its length.

test cases:
strDist("catcowcat", "cat") → 9
strDist("catcowcat", "cow") → 3
strDist("cccatcowcatxx", "cat") → 9

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

i want solution program for this program......

Given a string and a non-empty substring sub, compute the largest substring which starts and ends with sub and return its length.

test cases:
strDist("catcowcat", "cat") → 9
strDist("catcowcat", "cow") → 3
strDist("cccatcowcatxx", "cat") → 9

1> we are not here to do your homework

2> use strncmp() to solve your problem.

3> Try to solve it yourself. Its not very hard.

4> if u are stuk somewhere just post your problem here. We can help.

gud luck............

Edited by dkalita: n/a

0

>>wanted solution

I want a million dollars too -- will you give it to me ??? Kindly deposit it into my paypal account.

Hint to the solution: use strstr() to find the substring, then subtract two pointers (return value of strstr() and the original pointer)

char str = "Hello World";
strstr( str, "World") - str + strlen("World");

The above will crash if "World" is not contained in str.

Edited by Ancient Dragon: n/a

Votes + Comments
couldn't be better :)
LOL. Yeah, I'll take some too!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.