#include <iostream>
#include <cstring>
using namespace std;
//get two arrays of chars as main_str and sub_str and find sub_str in main_str and replace by *
void replace(char main_str[], char sub_str[], char replace_str[])
{
int main_str_len = strlen(main_str);
int sub_str_len = strlen(sub_str);
int replace_str_len = strlen(replace_str);
int i = 0;
int j = 0;
int k = 0;
while (i < main_str_len)
{
if (main_str[i] == sub_str[j])
{
j++;
if (j == sub_str_len)
{
for (k = 0; k < replace_str_len; k++)
{
main_str[i + k] = replace_str[k];
}
j = 0;
}
}
else
{
j = 0;
}
i++;
}
}
//test replace function
int main()
{
char main_str[] = "abcdabcd";
char sub_str[] = "ab";
char replace_str[] = "*";
replace(main_str, sub_str, replace_str);
cout << main_str << endl;
return 0;
}