-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstPatternMatchingAlgo.c
36 lines (32 loc) · 991 Bytes
/
firstPatternMatchingAlgo.c
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
#include<stdio.h>
void patternMatching1(char *mainString, char *query, int pos[100]){
int strLen=0, i, qStrLen=0, j, f, arrPos=0, found;
while(mainString[strLen]!='\0') strLen++;
while(query[qStrLen]!='\0') qStrLen++;
for(i=0; i<strLen-qStrLen; i++){
if(mainString[i]==query[0]) {
f=1;
for(j=1; j<qStrLen; j++){
if(mainString[i+j]!=query[j]) {
f=0;
break;
}
}
if(f==1){
pos[arrPos]=i+1;
arrPos++;
i+=qStrLen-1;
}
else i++;
}
}
}
int main(){
char str[100] = "Tomay Amar Shonar Bangla, Ami Tomay Valobashi! Tomay!", queryString[100] = "Tomay";
int pos[100], i;
for(i=0; i<100; i++) pos[i]=0;
i=0;
patternMatching1(str, queryString, pos);
while(pos[i]!=0) printf("%d\t",pos[i]-1), i++;
return 0;
}