/*********************************************************   
  TD d'Algorithmique IN202    
  ENSTA   
  Mardi 12 Decembre 2000    
    
  Pattern-matching naif   
      
                                        Guillaume Poupard  
*********************************************************/   
#include <stdio.h>  
#include <stdlib.h>   
#include <string.h>  
   
char Texte[]="Bonjour la terre !!!";  
   
int decalage_valide(char *P, char *T, int s)  
{   
  int i;  
  int m=strlen(P);   
    
  for(i=0;i<m;i++)   
    if (P[i]!=T[i+s])  
      return 0;   
  return 1;  
}   
  
int recherche(char *P, char *T)   
{  
  int n=strlen(T);   
  int m=strlen(P);  
  int s;   
    
  for(s=0;s<=n-m;s++)   
    if (decalage_valide(P,T,s))  
      return 1;   
  return 0;  
}   
  
   
int main(int argc, char * argv[])  
{   
  printf("%d\n",recherche("jour",Texte));  
  printf("%d\n",recherche("!!",Texte));   
  exit(0);  
}


syntax highlighted by Code2HTML, v. 0.9.1