grimoire/c/cosmic.c

33 lines
614 B
C

#include <stdio.h>
int match(const char *needle, const char *haystack) {
while(*haystack) {
if(*needle == '*' && *(needle + 1) == '*') {
needle += 1;
} else if(*needle == '*') {
if(*(needle + 1) == '\0') {
return 0;
} else if(*(needle + 1) == *haystack) {
needle += 1;
} else {
haystack += 1;
}
} else if(*needle == *haystack) {
needle += 1;
haystack += 1;
} else {
return 1;
}
}
return *needle != '\0';
}
int main(int argc, char **argv) {
if(argc != 3) {
return 1;
}
return match(argv[1], argv[2]);
}