Wednesday 28 November 2012

Naive pattern matching algorithm


//Naive pattern matching algorithm implementation.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 int n,m,s;
 clrscr();
 char t[200],p[200],count=0;
 printf("Enter the data for Naive Pattern Match Algorithm\n");
 printf("String: ");scanf("%s",t);
 printf("Pattern: ");scanf("%s",p);
 n=strlen(t);
 m=strlen(p);
 printf("Pattern Matched at:");
 for(s=0;s<n-m;s++)
 {
  for(int i=0;i<m;i++)
  {
   if(t[s+i]==p[i]) count++;
  }
  if(count==m)
  printf("%d\t",s);
  count=0;
 }
 getch();
}
//program written by Mars.

3 comments:

You are welcome, your comment helps me to make this blog more better.