its supposed to search string a for string b and once string a matches the requirments it should be printed alongside string b. anyway it does that but the output isnt
c c
c c
c c
what it should be but it shows double that for whatever reasons:
#include <iostream>
using namespace std;
int main()
{
string source= "a bb ccc dddd",
search="ccc";
for (int i=0; i< source.length(); i++)
{
if ((source[i] == search[0]) || (source[i+search.length()] == search[search.length()] ) )
{
for (int j=i,k=0; j<(i+search.length()); j++,k++)
{
if (source[j] == search[k]) { cout<< source[j] << " " << search[k] <<endl; }
}
}
}
cin.get();
return 0;
}