diff --git a/c/cosmic.c b/c/cosmic.c new file mode 100644 index 0000000..1cac97a --- /dev/null +++ b/c/cosmic.c @@ -0,0 +1,32 @@ +#include + +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]); +}