#include <iostream>
using namespace std;

const int MAX_SIZE = 256;

void removeSubstring(char[], char[]);
void inputString(char[], int);

int main() {

	char string[MAX_SIZE];
	inputString(string, MAX_SIZE);

	char secondString[MAX_SIZE];
	inputString(secondString, MAX_SIZE);

	// Removes all occurences of secondString from string.
	removeSubstring(string, secondString);

	cout << "Result: " << string << endl;

	return 0;
}

void inputString(char string[], int limit) {

	cout << "Input a stirng (max" << limit << "): ";
	cin.getline(string, limit);

}

bool substringOf(char subs[], char str[], int start) {
	
	for(int i = 0, j = start; subs[i] != '\0'; ++i, ++j) {
		if(subs[i] != str[j]) {
			return false;
		}
	}
	return true;
}

int stringLength(char string[]) {
	int i;
	for(i = 0; string[i] != '\0'; ++i);
	return i;
}

void removeSubstring(char from[], char subs[]) {

	int subsLen = stringLength(subs);
	int readIndex = 0;
	int writeIndex = 0;

	while(from[readIndex] != '\0') {
		if(from[readIndex] == subs[0] && substringOf(subs, from, readIndex)) {
			readIndex += subsLen;
			continue;
		}
		from[writeIndex] = from[readIndex];
		++writeIndex; 
		++readIndex;
	}	
	from[writeIndex] = '\0';
}
