0% found this document useful (0 votes)
18 views2 pages

AOA10

This document describes an experiment on naive string matching. The experiment includes a C program to find if a pattern exists within a given text using a naive algorithm. The program takes the text and pattern as input and returns the index if a match is found or -1 if no match.

Uploaded by

snehalparab183
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

AOA10

This document describes an experiment on naive string matching. The experiment includes a C program to find if a pattern exists within a given text using a naive algorithm. The program takes the text and pattern as input and returns the index if a match is found or -1 if no match.

Uploaded by

snehalparab183
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

****************************************************************

EXPERIMENT NO.10
NAME:-Pranali Khorje. Class:-SE(AIML) SUB:-
AOA LAB. Roll No.:- 26
****************************************************************
Source Program:
#include<stdio.h>
#include<conio.h>
int naivestringmatch(char text[100], char pattern[100]);
void main()
{
char text[100],pattern[100];
int status;
clrscr();
printf("\n enter the text :-->");
gets(text);
printf("\n enter the pattern :-->");
gets(pattern);
status = naivestringmatch(text,pattern);
if(status == -1)
{
printf("\n match not found!");
}
else
{
printf("\n match found on %d position !",status);
}
getch();
}
int naivestringmatch(char text[100],char pattern[100])
{
int n,m,i,j,count = 0,temp = 0;
n = strlen(text);
m = strlen(pattern);
for(i=0;i<n-m;i++)
{
temp++;
for(j=0;j<m;j++)
{
if(text[i+j] == pattern[j])
count ++;
}
if(count == m)
return temp;
count = 0;
}
return -1;
}
Output:

enter the text :-->This is string matching algorithm


enter the pattern :-->string
match found on 9 position !

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy