#include #include #include // matchesAt(word, pos, piece) returns true if piece appears in word // starting exactly at index pos, false otherwise // requires: word and piece are valid strings // and 0 <= pos <= strlen(word) bool matchesAt(const char *word, int pos, const char *piece){ for (int k = 0; piece[k] != '\0'; k++) { // if word ends early, its zero character will not equal piece[k] if (word[pos + k] != piece[k]) { return false; } } return true; } // lookBehind(check, s_sub, word) removes every occurrence of s_sub in word // that is immediately preceded by check, repeating on the updated word // until no more can be removed // requires: check, s_sub and word are valid strings // word is a modifiable array // effects: mutates word void lookBehind(const char *check, const char *s_sub, char *word){ int checkLength = strlen(check); int subLength = strlen(s_sub); if (subLength == 0) { return; } int i = 0; while (word[i] != '\0') { int subStart = i + checkLength; if (matchesAt(word, i, check) && matchesAt(word, subStart, s_sub)){ // slide the rest of word (and end character) left over s_sub int j = subStart; while ((word[j] = word[j + subLength]) != '\0') { j++; } // removing can create a new match, so start over i = 0; } else{ i++; } } }