Originally Posted by
darren78
I think it will work. Will try it this evening and post the solution.
Isn't it great when you figure something out!!!
It was a very simple change in the end:
Code:
char* findx(char* s, char* x)
{
int lens = strlen(s);
int lenx = strlen(x);
int count = 0;
int found = 0;
for(int i = 0; i < lenx; ++i) {
for(int j = count; j < lens; ++j) {
if(s[j] == x[i]) {
++ count;
break;
}
count = 0;
}
if(count == lens){
++found;
count = 0;
i = i-(lens-1); // only part I changed!
}
}
cout << found;
return s;
}
It seems to work fine with the test data I used. I inputted various lengths of 'x' strings and it was correct on each occasion!
Anybody any suggestions to make it more efficient or is this fine as it is?
Thanks.