#include <stdio.h>
#include <stdlib.h>
char str[100], pat[100], rep[100], ans[100];
int i, j, m, c, k, flag;
void strs() {
flag = 0;
while (str[c] != '\0') {
if (str[m] == pat[i]) {
i++;
m++;
if (pat[i] == '\0') {
flag = 1;
for (k = 0; rep[k] != '\0'; k++, j++) {
ans[j] = rep[k];
}
i = 0;
c = m;
}
} else {
ans[j] = str[c];
j++;
c++;
m = c;
i = 0;
}
}
ans[j] = '\0';
}
int main() {
printf("Enter the string:\n");
fgets(str, sizeof(str), stdin);
printf("Enter the pattern:\n");
fgets(pat, sizeof(pat), stdin);
printf("Enter the replacement:\n");
fgets(rep, sizeof(rep), stdin);
i = j = m = c = 0;
strs();
if (flag == 1) {
printf("Result: %s", ans);
} else {
printf("Pattern not found in the string.");
}
return 0;
}