#include #include #include #include const int iMainLength = 100; const int iPatternLength = 20; const int iKeyLength = 20; int search_rule(char[], char[]); void run_rule(char[], char[], char[]); void main() { char strMain[iMainLength]; char strPattern1[iPatternLength], strPattern2[iPatternLength], strPattern3[iPatternLength]; char strKey1[iKeyLength], strKey2[iKeyLength], strKey3[iKeyLength]; int k1, k2, k3; while(true) { printf("Enter Main string: "); gets(strMain); printf("\n\r--------------------------------------------------------------------------------"); printf("First pattern: "); gets(strPattern1); printf("First output: "); gets(strKey1); printf("\n\n\rSecond pattern: "); gets(strPattern2); printf("Second output: "); gets(strKey2); printf("\n\n\rThird pattern: "); gets(strPattern3); printf("Third output: "); gets(strKey3); if((strPattern1==strKey1) || (strPattern2==strKey2) || (strPattern3==strKey3)) { clrscr(); printf("The patterns was wrong"); printf("\n\rPattern 1: %s\tKey 1: %s", strPattern1,strKey1); printf("\n\rPattern 2: %s\tKey 2: %s", strPattern2,strKey2); printf("\n\rPattern 3: %s\tKey 3: %s", strPattern3,strKey3); } else break; } k1=search_rule(strMain,strPattern1); k2=search_rule(strMain,strPattern2); k3=search_rule(strMain,strPattern3); while((k1 > 0) || (k2 > 0) || (k3 > 0)) { while ((k1 > 0) || (k2 > 0 )) { while (k1 > 0) { run_rule(strMain,strPattern1,strKey1); k1=search_rule(strMain,strPattern1); } run_rule(strMain,strPattern2,strKey2); k1=search_rule(strMain,strPattern1); k2=search_rule(strMain,strPattern2); } run_rule(strMain,strPattern3,strKey3); k1=search_rule(strMain,strPattern1); k2=search_rule(strMain,strPattern2); k3=search_rule(strMain,strPattern3); } printf("The result string is : %s", strMain); getch(); } int search_rule(char strMain[], char strPattern[]) { int iTime=0; char strTemp[iPatternLength]; //az aval reshteye asli shoro karde va 1 zir reshte be tul reshteye olgo az an joda mikonad for(int i=0;i