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
");

 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 ",s);
  count=0;
 }
 getch();
}
//program written by Mars.

Related Posts by Categories

0 comments:

Post a Comment

Blog Archive

Powered by Blogger.