int overlap( char *ptr1 , char *ptr2 );
int pattern(char *ptr3,char *ptr4);
int main()
{
char strg1[] = "To those who do not know mathematics it is difficult to get across a real feeling as to the beauty, the deepest beauty, of nature. If you want to learn about nature, to appreciate nature, it is necessary to understand the language that she speaks in.", strg2[]= "nature";
char *ptr1(strg1), *ptr2(strg2);
overlap(ptr1,ptr2);
You are counting the second T in a pair as the first T in the following pair; in essence, you are counting the same letter twice in some cases.
When you find a TT pair, add to your count, and then move the pointer keeping track of where you are in the string forwards another element, so that you don't count the second T as the first T in a new pair.
Can't you use std::string? Anyway, I believe the problem is you're always advancing your index by one (i.e. ptr1++ or ptr3++) instead of advancing it by the length of the substring you're looking for so you won't count the same characters twice.
The crux of your problem is that when you find a match, you need to advance beyond that match and then keep looking.
Accordingly, the advance you make when you've found a match should not be of size one character, but of however many characters in the match.
So, ptr3++ advances only one letter, but TT is of size two, so you need to advance two letters.
ptr3 = ptr3 + 2;
A nicer way of doing that is to let the code figure out how far to advance. The cstring function strlen returns the number of characters in a char array, so you could use
ptr3 = ptr3 + strlen(ptr4);
as ptr4 is the word you're trying to match, so that is how many letters you need to advance to make sure you don't try to match any letters you've already decided are a match.
Your functions overlap and pattern are almost identical, changing only in minor text put to screen. The idea of functions is to save having to write out the same code repeatedly. Having two identical functions seems a bit silly. :)