#include #include int str_match(const char s[], const char p[], int strict) { // takes string and pattern and strict flag // should return if the characters in the pattern appear in the string in the same order // strict should also check for difference in capital letters // it does not matter whether there are characters in between (other) int ls = strlen(s); int lp = strlen(p); int o = -1; // Loop the patterns and the string for each pattern for (const char *cp = p; *p != '\0'; p++) { for (int j = 0; j < ls; j++) { char chp = *p; char cha = s[j]; if (!strict) { chp = (char) tolower(chp); cha = (char) tolower(cha); } if (cha == chp) { // Break condition if (j < o) { return 0; } // Set the new occurence o = j; break; } } } return 1; } #include int main() { printf("%d\n", str_match("Hallo Welt", "alo", 1)); printf("%d\n", str_match("Hallo Welt", "alo", 0)); printf("%d\n", str_match("Hallo Welt", "alho", 1)); printf("%d\n", str_match("Hallo Welt", "alho", 0)); }