grimoire/c/cosmic.c

33 lines
636 B
C
Raw Normal View History

int match(const char *needle, const char *haystack) {
2022-01-19 19:01:06 +00:00
while(*haystack || *needle) {
if(*needle == '*') {
if(*(needle + 1) == '\0') {
2022-01-14 16:19:31 +00:00
return 1;
} else if(*(needle + 1) == '*') {
needle += 1;
} else if(*(needle + 1) == *haystack) {
needle += 1;
2022-01-19 19:01:06 +00:00
} else if(*haystack == '\0') {
needle += 1;
} else {
haystack += 1;
}
} else if(*needle == *haystack) {
needle += 1;
haystack += 1;
} else {
2022-01-14 16:19:31 +00:00
return 0;
}
}
2022-01-19 19:01:06 +00:00
return 1;
}
int main(int argc, char **argv) {
if(argc != 3) {
return 1;
}
return !match(argv[1], argv[2]);
}