grimoire/c/cosmic.c

33 lines
636 B
C

int match(const char *needle, const char *haystack) {
while(*haystack || *needle) {
if(*needle == '*') {
if(*(needle + 1) == '\0') {
return 1;
} else if(*(needle + 1) == '*') {
needle += 1;
} else if(*(needle + 1) == *haystack) {
needle += 1;
} else if(*haystack == '\0') {
needle += 1;
} else {
haystack += 1;
}
} else if(*needle == *haystack) {
needle += 1;
haystack += 1;
} else {
return 0;
}
}
return 1;
}
int main(int argc, char **argv) {
if(argc != 3) {
return 1;
}
return !match(argv[1], argv[2]);
}