int findinstring(const char *inner, const char *outer, int start) {
int x = 0; // When it begins to count within the substring
bool searchflag = false; // To see if it's been found
for(int i = start; outer[i] != 0; i++) {
searchflag = true; // Sets it true, for now
for(x = 0; inner[x] != 0; x++)
if(outer[i + x] != inner[x])
searchflag = false;
/* ^ Checks to see if every occurence is true.
If but one is false, it will then set searchflag to false saying to continue the search. */
if (searchflag == true) // Tells it to quit the loop in this case, because we're now done.
break;
}
if (searchflag == true)
return i; // Returns pos if it could find one
else
return -1; // This is what it returns if it could not.
}
^ This above is a working function I created on my own. With this it will find the first occurence of a substring within a string from the point in the main string you have it start from. It will then return the first position of the first occurence of the substring it can find from your starting point, if it can find it; if it cannot find it from your starting point, then it will return -1.




Reply With Quote