QUOTE(martina @ 13 Mar, 2007 - 04:48 PM)

Hi!
Need some help in writing a code in C!
I want to compare two strings, if they both contain any (at least) 4-letter substring which is the same.
For example:
'description' and 'crippled' both contain the same substring 'crip'.
Can I use here strstr() anyhow?
Many thanks to anyone posting an answer!
Best,
Martina
well, I don't think that strstr will be useful in this case.
It would be better to write a function for that.
Writing a logic for it would not be that difficult.
All you need to do is something like this :
CODE
found=-1;
for(i=0,j=0;i<strlen(word1);)
{
if(word1[i]==world2[j])
{
k=i;
l=j;
count=0;
while(k<strlen(word1) && l<strlen(word2) && word1[k++]==word2[l++]) count++;
if(count>=4)
{ found = i; break; }
}
j++;
if(j==strlen(word2))
{ i++; j=0; }
}
if(found>=0)
{
for(i=found;i<count;i++)
printf("%c",word1[i]);
}
else
printf("No common pattern found.");
Please note that I wrote it on the fly. This code is not tested even not compiled also. So please take the logic out of it and make your code.
Hope this will help you.