int overlap(const char *s1, const char *s2){
int i = 0;
while (s1[i] && s2[i] && s1[i] == s2[i])
i++;
return i;
}
This returns the length of the substring overlap between the two strings it takes as input. However, if the two strings are:
abcdefg
1234efg
it returns an overlap of 0 because it can only read overlaps that start at the beginning of the strings, can someone modify or help me to make it so that it can read overlaps no mantter where they are in the strings?
well i have thought this question again.
i think you want an overlap at the same index in each string.
pay attention to the character ‘\0’ in the end of each string.
so we can write the codes as the following:
for “abcdefg” and “1234efg”, it will return 3.