Et raté !
godzil@localhost ~ $ cat strsrch.c
#include<stdio.h>
#include<string.h>
void recherche (char ch1[],char ch2[])
{
int i=0;int j=0;
if(strlen(ch1)<=strlen(ch2))
{
while( (i<strlen(ch1)) && (j<strlen(ch2)) )
{
if(ch1[i]==ch2[j])
{
i++;
j++;
}
else
{
i=0;
j++;
}
}
printf("i= %d j= %d\n",i,j);
if ( i==strlen(ch1))
printf("le mot est trouve");
else
printf("le mot n'est pas trouve");
}
else
printf("chaine courte");
}
int main()
{
char chaine[] = "coucoucou !";
char mot[] = "coucou !";
recherche(mot, chaine);
}
godzil@localhost ~ $ gcc strsrch.c
godzil@localhost ~ $ ./a.out
i= 0 j= 11
le mot n'est pas trouvegodzil@localhost ~ $