From a4000ec9b342dc10140a23445ee6a8aaea3e0f39 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Thu, 13 Jan 2022 12:35:48 -0600 Subject: [PATCH] c/cosmic.c: A barebones globals implementation --- c/cosmic.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 c/cosmic.c 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]); +}