/*voici mon algorithme:*/
#include<stdio.h>
#include<string.h>
#include<conio.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)) || (i<=strlen(ch1)) ))
{
if(ch1[i]==ch2[j])
{
i++;
j++;
}
else
{
i=0;
j++;
}
}
printf("i= %d j= %d\n",i,j);
if (i-1==strlen(ch1))
printf("le mot est trouve");
else
printf("le mot n'est pas trouve");
}
else
printf("chaine courte");
}
int main()
{
char mot[10];
char motsource[20];
printf("donner la chaine source:\n");
gets(motsource);
printf("donner le mot a rechercher:\n");
gets(mot);
recherche(mot,motsource);
getch();
}
déja "if (i-1==strlen(ch1))" est semantiquement foireux..