-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpattern_matching2.c
76 lines (70 loc) · 1.03 KB
/
pattern_matching2.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void read();
void display();
void pattern();
char mainstr[100],patstr[100],repstr[100],tempstr[100];
void main()
{
system("clear");
read();
system("clear");
display();
pattern();
}
void read()
{
printf("Enter the main string ,pattern string and replacement string :\n");
gets(mainstr);
gets(patstr);
gets(repstr);
}
void display()
{
printf("The entered main string ,pattern string and replacement string are:\n");
puts(mainstr);
puts(patstr);
puts(repstr);
}
void pattern()
{
int mi=0,pi=0,ti=0,ci=0,ri=0,flag=0;
while(mainstr[mi]!='\0')
{
if(mainstr[ci]==patstr[pi])
{
ci++;
pi++;
if(patstr[pi]=='\0')
{
for(ri=0;repstr[ri]!='\0';ri++)
{
tempstr[ti]=repstr[ri];
ti++;
}
mi=ci;
pi=0;
flag=1;
}
}
else
{
tempstr[ti]=mainstr[mi];
ti++;
mi++;
ci=mi;
pi=0;
}
}
if(flag==0)
{
printf("Pattern does not found.\n");
}
else
{
tempstr[ti]='\0';
printf("The final string is :");
puts(tempstr);
}
}