Occurences of a string in another string.
Okay, so i've written the function and it seems to work. The outline was to write a function with this signature: char* findx(char*s, char*x), that finds multiple occurences of string s in x.
My code is:
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;
}
}
cout << found;
return s;
}
As I said, this seems to work fine. Can anybody see anything wrong with it?
Thanks.