avatar
Untitled

Guest 32 4th Dec, 2019

MARKUP 0.87 KB
                                           
                         #include <stdio.h>
#include <string.h>

char str[100], pat[100], rep[100], ans[100];
int i, j, m, c, k;

int flag = 0;

void readinput()
{
	printf("enter the main string:");
	gets(str);
	printf("enter the pattern string:");
	gets(pat);
	printf("enter replacement string:");
	gets(rep);
}

void patternmatch()
{
	i = j = m = c = k = 0;
	
	while (str[c] != '\0')
	{
		i++;
		m++;

		if (str[m] == pat[i])
		{
			if (pat[i] == '\0')
			{
				for (k = 0; rep[k] != '\0'; k++, j++)
					ans[j] = rep[k];
				i = 0;
				c = m;
				flag=1;
			}
		}
			else
			{
				ans[j] = str[c];
				j++, c++;
				m = c;
				i = 0;
			}
		
	}

	ans[j] = '\0';
}

int main()
{
	readinput();
	patternmatch();
if(flag==1)
puts(ans);
else
printf("Pattern string not found");

}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes