forked from 1KS20AI001-Abhishek/DSA_LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab_prog02.c
48 lines (45 loc) · 994 Bytes
/
Lab_prog02.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
//DSA_LAB_PROGRAM_2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//finding pattern in string
void findpat(char *str, char *pat, char *rep){
int i,m,k,c,j,flag=0;
char res[100];
i = m = c = j = 0;
while ( str[c]!='\0'){
if (str[m] == pat[i]){
i++;
m++;
if ( pat[i]=='\0'){
for(k=0; rep[k]!='\0'; k++){
res[j] = rep[k];
j++;
flag=1;
}
i=0;
c=m;
}
}
else{
res[j] = str[c];
j++;
c++;
m = c;
i=0;
}
}
if(flag==0){
printf("pattern not found\n");
}
else{
res[j] = '\0';
printf("\nThe resultant string is: %s\n" , res);
}
}
int main(){
char str[100], pat[100], rep[100];
scanf("%s %s %s", &str, &pat, &rep);
findpat(str, pat, rep);
return 0;
}