1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| char phrase[50],mot[30],tmp[30];
int i,j,trouve=0,k;
printf("\n entrez une phrase : ");
gets(phrase);
printf("\n entrez le mot a rechercher : ");
gets(mot);
tmp[strlen(mot)]='\0';
for(i=0;i<=(strlen(phrase)-strlen(mot));i++)
{
for(j=i;j<i+strlen(mot);j++)
{
tmp[j-i]=phrase[j];
}
k=i+strlen(mot);
if(i!=0)
{
if((strcmp(tmp,mot)==0)&&((phrase[k]==' ')||(phrase[k]==',')||(phrase[k]==';'))&&((phrase[i-1]==' ')||(phrase[i-1]==',')||(phrase[i-1]==';')))
{ printf("\nMot trouve");
trouve=1;
break;
}
}
else if((strcmp(tmp,mot)==0)&&((phrase[k]==' ')||(phrase[k]==',')||(phrase[k]==';')))
{ printf("\nMot trouve");
trouve=1;
break;
}
if((strcmp(mot,tmp)==0)&&(k==strlen(phrase)))
{ printf("\nMot trouve");
trouve=1;
break;
}
}
if(!trouve) printf("\nMot non trouve");
return 0; |